Is Zig's New Writer Unsafe?

The example in the post is using the “direct mode” of std.compress.zstd.Decompress (i.e. giving it a zero-length buffer) which actually has much more unsafety than detailed in the post:

(the issue is about flate but it applies to zstd as well)

Any usage of Decompress in “direct mode” that calls into vtable.rebase/discard/readVec is guaranteed to trigger illegal behavior.

See this comment for context. As I commented here, I think there is room for improvement on the documentation surrounding this, but there’s also some inherent problems with this use case that will hopefully get some attention soon.

2 Likes