Zstd: ZSTD_estimateCStreamSize misreports for "fast" negative levels

Created on 23 Nov 2018  路  2Comments  路  Source: facebook/zstd

Today, the result is initialized to zero, and the routine enumerates levels from 1 up to the supplied level. However, negative levels are less than one, so the return value is always zero (which is surely inaccurate).

It isn't clear to me why a higher level would ever use less memory than a lower level, so I am not sure that the enumeration is needed at all. If it is, this can be fixed by starting enumeration at ZSTD_minCLevel() (and skip the non-level 0).

If the enumeration is not needed, maybe ZSTD_estimateCStreamSize() can be entirely replaced by ZSTD_estimateCStreamSize_internal().

Thanks!

bug

All 2 comments

You're correct.
This function was only tested with level 1+ .
Indeed, it must be updated now that negative compression levels are also possible.

We have the enumeration because it is highly unintuitive for higher levels to use less memory than lower levels, but it is entirely possible. We want to provide the guarantee that you can size the memory large enough for the highest level, and be able to use any level lower than it as well.

Was this page helpful?
0 / 5 - 0 ratings