fix: prevent index out of range on long frag tables #30
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.
Hi! Thanks for a pure-Go implementation of SquashFS reading. I think I found a bug. This PR is a proposed fix I'm curious whether you'd be interested in it. It's a bit of a large diff for such a fix, but I really wanted to get the edge cases of block boundaries, last blocks with an incomplete set of records, etc, under unit test, and this seemed like the best approach to me. If you'd like me to take a different approach, let me know.
For context, I'm a maintainer on Syft (an open source SBOM tool) that depends on a fork of this library (we can't depend on this library directly because of how LZO is licensed). This was reported to Syft on anchore/syft#3390. I'm trying to contribute the fix as far upstream as I can.
Previously, reading fragment 512 would panic with index out of range. Fix that panic by introducing an abstraction over reading blocks of items, caching the intermediate result, and returning an item at a particular index. The primary goal of this abstraction is to make edge cases like requesting items on page boundaries easy to unit test for.
Additionally, fix unit tests by making t.Fatal calls protected by nil checks on the error values.
Questions
low/reader.go
that read a table incrementally to use this approach?t.Fatal
calls in some tests. Is that getting you something I'm not realizing? It seems incorrect to me.