Repository navigation
Conversation
…7Store C frees each buffer and leaves size and the freed pointers as they were. The port nulled each pointer and set size to 0. This reproduces C's dangling state and is not meant to be merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Leave the store's size and pointers alone in ZopfliCleanLZ77Store, as C does
Problem
ZopfliCleanLZ77Store(C, Rust) frees a store's buffers. C just frees each pointer and leavessizeand the (now dangling) pointers as they were. The port frees each buffer, nulls the pointer, and setssizeto 0. So afterClean, the struct a caller still holds reads differently. For example, cleaning a store of 289 commands:store.sizeafter CleanQuestion
Which behaviour do we want: C's or the Rust port's? Specifically, after
ZopfliCleanLZ77Store, should the struct keep its oldsizeand (freed) pointers (like the C source), or be reset to size 0 with null pointers (like the Rust port)?This PR implements C's behaviour.
Fix
Rust_ZopfliCleanLZ77Storefrees each buffer withlibc::freewithout nulling it, and drops thestore.size = 0line:Replayed on the 289-command record, before and after:
ZopfliCleanLZ77Store.sizeThe compared
sizenow matches C, and the divergence closes.Downstream check. The normal path is untouched:
ZopfliGzipCompresson the repository'sREADMEgives the same 831-byte stream from the port before and after this patch, andgzip.decompressrestores the file. C's stream is also 831 bytes but differs in a few bytes, for a separate reason (#213).Notes for review:
freemakes them dangling, and leavingsizenon-zero means a later read of the struct walks freed memory. The port's reset (null pointers, size 0) is the memory-safe choice and catches a double-free or use-after-free; C's version does not. The PR exists only to show the divergence and ask which post-Cleanstate is intended, not to ship.