ArjunD3456 opened a new pull request, #4098:
URL: https://github.com/apache/avro/pull/4098

   ## What is the purpose of the change
   
   `decode_deflate` and `decode_lzma` in `lang/c/src/codec.c` grow the output 
buffer by doubling it with `avro_realloc` whenever the decompressor runs out of 
room, and assign the result straight back to `block_data`. If that realloc 
fails, `decode_deflate` sets `next_out = NULL + total_out` while `avail_out` 
still advertises the doubled size, so `inflate()` carries on writing 
decompressed bytes to an absolute address equal to the output produced so far. 
How far a block inflates is decided by the compressed data in the container 
file, so a few KiB of deflate that expands past what the allocator will hand 
out (RLIMIT_AS, a 32-bit address space, or a bounded allocator installed 
through `avro_set_allocator`) ends in a write through a wild pointer. 
`decode_lzma` has the same unchecked realloc; liblzma rejects the NULL output 
buffer there, but the previous buffer is leaked. On failure the old buffer is 
now kept and the decoder returns an error, and the inflate stream is reset so 
the codec 
 can still decode the next block.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
   - Added `test_avro_codec_alloc` (registered with `add_avro_test_checkmem`). 
It installs an allocator that refuses requests over 1 MiB, encodes 4 MiB of 
zeros with each available codec, and checks that `avro_codec_decode` fails 
cleanly.
   - Before the fix the deflate case crashes with an access violation writing 
to address `0x100000` (NULL + the 1 MiB already produced), and the lzma case 
leaves one allocation outstanding. After the fix both decodes return an error 
and nothing is leaked.
   - I ran the test against `codec.c` built with zlib 1.3.1 and liblzma 5.4.6 
on clang with `-W -Wall`; no new warnings. I could not run the full `./build.sh 
test` suite on that machine, so CI is the first full run.
   
   ## Documentation
   
   - Does this pull request introduce a new feature? no
   - If yes, how is the feature documented? not applicable
   


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