Copilot commented on code in PR #3853:
URL: https://github.com/apache/avro/pull/3853#discussion_r3567609098
##########
lang/c/src/codec.c:
##########
@@ -331,6 +418,15 @@ static int decode_deflate(avro_codec_t c, void * data,
int64_t len)
{
err = inflate(s, Z_FINISH);
+ // Reject a block that decompresses to more than the allowed
maximum,
+ // to guard against unbounded allocation from a high-ratio
block.
+ if ((int64_t) s->total_out > max_len) {
+ inflateEnd(s);
+ avro_set_error("Decompressed block size exceeds the
maximum allowed of %lld bytes",
+ (long long) max_len);
+ return 1;
+ }
Review Comment:
On the over-limit path, decode_deflate() calls inflateEnd(s) and returns.
That permanently tears down the codec's zlib inflate stream; any subsequent
avro_codec_decode() with the same codec will fail (and reset_deflate() will
later call inflateEnd again on an already-ended stream). Prefer leaving the
codec reusable by resetting the stream state instead of ending it here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]