Skip to content

zbuffer: handle a zero init_size and sizes wider than zlib's counters - #1205

Open
b84330808 wants to merge 1 commit into
msgpack:c_masterfrom
b84330808:fix-zbuffer-size-handling
Open

b84330808 wants to merge 1 commit into
msgpack:c_masterfrom
b84330808:fix-zbuffer-size-handling

Conversation

@b84330808

Copy link
Copy Markdown

Fixes #1198, fixes #1199, and two more size problems in the same functions:

  • msgpack_zbuffer_init(zbuf, level, 0) stored 0, so the first write made a zero-size buffer and failed, and the next realloc(ptr, 0) freed it while zbuf->data kept the pointer, which destroy then freed again. 0 now means the default, as in msgpack_vrefbuffer_init().
  • msgpack_zbuffer_expand() doubled the size with no overflow check. It now returns false.
  • msgpack_zbuffer_write() cast len to the 32-bit avail_in, so a write of 4 GiB + 1 bytes compressed 1 byte and returned 0. Long writes now go to zlib in several steps.
  • expand cast the free space to the 32-bit avail_out. At exactly 4 GiB free that is 0, so write fails and flush spins forever once the output reaches 4 GiB. It now saturates.

zbuffer_sizes_c gets its own translation unit with a stand-in deflate() that only counts input, so the tests don't need 4 GiB of data. The size tests fail without the header change (the expand one on both 32-bit and 64-bit) and pass with it.

- msgpack_zbuffer_init(zbuf, level, 0) stored 0, so the first write made
  a zero-size buffer and failed, and the next realloc(ptr, 0) freed it
  while zbuf->data kept the pointer, which destroy then freed again
  (msgpack#1198). 0 now means the default size, as in msgpack_vrefbuffer_init().
- msgpack_zbuffer_expand() doubled the size without an overflow check
  (msgpack#1199). It now fails instead.
- msgpack_zbuffer_write() cast len to the 32-bit avail_in, so a write of
  4 GiB or more compressed only (len mod 2^32) bytes and returned 0. Long
  writes now go to zlib in several steps.
- expand also cast the free space to the 32-bit avail_out. At exactly 4
  GiB free that is 0, so write failed and flush spun forever once the
  output reached 4 GiB. It now saturates.

Fixes msgpack#1198
Fixes msgpack#1199
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.33%. Comparing base (eabfe29) to head (fd5cf2c).
⚠️ Report is 13 commits behind head on c_master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##           c_master    #1205      +/-   ##
============================================
+ Coverage     57.47%   62.33%   +4.86%     
============================================
  Files            10       10              
  Lines          1124     1147      +23     
  Branches        129      140      +11     
============================================
+ Hits            646      715      +69     
+ Misses          478      432      -46     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants