Add one extra byte to return value of deflateBound for small lengths.#1236
Add one extra byte to return value of deflateBound for small lengths.#1236Dead2 merged 2 commits intozlib-ng:developfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1236 +/- ##
===========================================
- Coverage 87.95% 87.38% -0.58%
===========================================
Files 114 114
Lines 10147 10147
Branches 2539 2555 +16
===========================================
- Hits 8925 8867 -58
+ Misses 972 957 -15
- Partials 250 323 +73
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
8522b2e to
d201fa1
Compare
…for small lengths due to shift returning 0. * Treat 0 byte input as 1 byte input when calculating compressBound and deflateBound
d201fa1 to
df44db5
Compare
@Dead2 Now it returns one extra byte at lengths 17 and 25... I didn't try longer than 32 bytes input as the pattern is already clear, every 8 bytes it returns one more extra byte. |
|
It would be better imo to add this to google test framework. |
|
@nmoinvaz It's kinda work in progress... I'm not good at writing tests using google test framework... |
* Test both compressBound() and deflateBound() as those share same code fragment.
35a5603 to
c0eeba5
Compare
|
Added test for compressBound() too, it's obvious it also would have failed with input length of 0, as I added 2 extra bytes in that case. For other lengths, there is now enough spare bytes to allow even uncompressible data. Tested with bytes filled with for loop to simulate worst case scenario. |
Changes since 2.0.6: - Fix CVE-2022-37434 #1328 - Fix chunkmemset #1196 - Fix deflateBound too small #1236 - Fix Z_SOLO #1263 - Fix ACLE variant of crc32 #1274 - Fix inflateBack #1311 - Fix deflate_quick windowsize #1431 - Fix DFLTCC bugs related to adler32 #1349 and #1390 - Fix warnings #1194 #1312 #1362 - MacOS build fix #1198 - Add invalid windowBits handling #1293 - Support for Force TZCNT #1186 - Support for aligned_alloc() #1360 - Minideflate improvements #1175 #1238 - Dont use unaligned access for memcpy #1309 - Build system #1209 #1233 #1267 #1273 #1278 #1292 #1316 #1318 #1365 - Test improvements #1208 #1227 #1241 #1353 - Cleanup #1266 - Documentation #1205 #1359 - Misc improvements #1294 #1297 #1306 #1344 #1348 - Backported zlib fixes - Backported CI workflows from Develop branch
Changes since 2.0.6: - Fix CVE-2022-37434 #1328 - Fix chunkmemset #1196 - Fix deflateBound too small #1236 - Fix Z_SOLO #1263 - Fix ACLE variant of crc32 #1274 - Fix inflateBack #1311 - Fix deflate_quick windowsize #1431 - Fix DFLTCC bugs related to adler32 #1349 and #1390 - Fix warnings #1194 #1312 #1362 - MacOS build fix #1198 - Add invalid windowBits handling #1293 - Support for Force TZCNT #1186 - Support for aligned_alloc() #1360 - Minideflate improvements #1175 #1238 - Dont use unaligned access for memcpy #1309 - Build system #1209 #1233 #1267 #1273 #1278 #1292 #1316 #1318 #1365 - Test improvements #1208 #1227 #1241 #1353 - Cleanup #1266 - Documentation #1205 #1359 - Misc improvements #1294 #1297 #1306 #1344 #1348 - Backported zlib fixes - Backported CI workflows from Develop branch
Due to right shift by 3 in DEFLATE_QUICK_OVERHEAD() macro, the return value of deflateBound() is 1 too small for lengths smaller than 9.
See #1235.