diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2022-11-24 11:15:59 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2022-11-24 11:15:59 +0300 |
commit | 6b878fe29adf0ad954334e8988173815c860a649 (patch) | |
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.
-rw-r--r-- | pb_decode.c | 6 |
1 files changed, 5 insertions, 1 deletions
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 @@ bool checkreturn pb_read(pb_istream_t *stream, pb_byte_t *buf, size_t count) return false; #endif - stream->bytes_left -= count; + if (stream->bytes_left < count) + stream->bytes_left = 0; + else + stream->bytes_left -= count; + return true; } |