by loftsy · 2y ago · 0 comments
This kind of change is difficult to make without mistakes because it silently changes the assumptions made when code calling dict_put() was originally written. ALL call sites would need to be audited to ensure they are not overflowing the dictionary size.
The diff I am referring to is here:
https://git.tukaani.org/?p=xz.git;a=commitdiff;h=de5c5e41764...
dict->pos == dict->limit
and not dict->pos >= dict->limit
if you can get one call of dict_put somewhere to pass the limit, all later calls of dict_put_safe will happily overwrite memory and not actually be safe.This is the kind of optimization I might have done in C 10 years ago. But coming back from Rust, I wouldn't consider it any more. Rust, despite its focus on performance, will simply not allow it (without major acrobatics). And you can usually find a way to make the compiler optimize it out of the critical path.
This would give you a controlled relative write primitive if you can repeatedly call this function in a loop and going OOB.
Zstd has a number of benefits over Xz that may warrant its use as a replacement of the latter, and this will likely be a motivating factor to do so. But calling it entirely rotten is going way too far IMO
XZ offers slightly better compression on average, but decompression is far slower than Zstd.
If you need an unsafe call, you add a dict_put_unsafe(). That again should of course be rejected in a code review.