Copilot commented on code in PR #3853:
URL: https://github.com/apache/avro/pull/3853#discussion_r3567429940


##########
lang/c/src/codec.c:
##########
@@ -483,11 +598,38 @@ static int decode_lzma(avro_codec_t codec, void * data, 
int64_t len)
 
                codec->used_size = write_pos;
 
-               // If it ran out of space to decode, give it more!!
-               // It will continue where it left off because of read_pos and 
write_pos.
+               // Reject a block that decompresses to more than the allowed 
maximum,
+               // to guard against unbounded allocation from a high-ratio 
block.
+               if ((int64_t) write_pos > max_len) {
+                       avro_set_error("Decompressed block size exceeds the 
maximum allowed of %lld bytes",
+                                      (long long) max_len);
+                       return 1;
+               }

Review Comment:
   In decode_lzma, the decompressed-size guard casts `write_pos` (size_t) to 
int64_t: `if ((int64_t) write_pos > max_len)`. If `write_pos` ever exceeds 
INT64_MAX, that cast can wrap negative and bypass the size cap, undermining the 
decompression-bomb protection. Compare using size_t (or another unsigned type 
wide enough for size_t) instead of narrowing `write_pos` to int64_t.



-- 
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]

Reply via email to