Fix repeated binary segment bug #10588
Open
+33
−3
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.
The following snippet reads garbage memory and even often triggers segfaults. It barely ever happens with small Ns, but for around larger than 40 it is almost guaranteed to segfault in my machine.
I found this while trying to write some tests for bencharking dns packet parsing logic. It did not trigger with only two labels, but with three it is enough. These labels trigger or fail to trigger too:
My findings:
When the same binary variable is used multiple times in a single bs_create_bin instruction (e.g.,
<<Label/binary, Label/binary, Label/binary>>), theprivate_appendoptimization was incorrectly applied. This caused memory corruption because:private_appendto destructively extend the binaryErlSubBitsstructure is modified to reflect the new sizeThe fix adds a check to ensure that before setting
first_fragment_diesto true (which enablesprivate_append), we verify the first fragment variable doesn't appear in any other segment of the instruction.