commit | 6b878fe29adf0ad954334e8988173815c860a649 | [log] [tgz] |
---|---|---|
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | Thu Nov 24 10:15:59 2022 +0200 |
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | Thu Nov 24 10:15:59 2022 +0200 |
tree | 2caf992c4d71fad18b6596ebe5b2c55762095d64 | |
parent | eeda15ed4e899cd3d404abf74c1d60e50eb6f790 [diff] |
Safeguard substraction in pb_read() (#697) Previously a custom stream callback could modify bytes_left, causing the substraction to wrap.
diff --git a/pb_decode.c b/pb_decode.c index 5405c87..58ee5f7 100644 --- a/pb_decode.c +++ b/pb_decode.c
@@ -111,7 +111,11 @@ return false; #endif - stream->bytes_left -= count; + if (stream->bytes_left < count) + stream->bytes_left = 0; + else + stream->bytes_left -= count; + return true; }