fix: prevent index out of range on long frag tables

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.
This commit is contained in:
Will Murphy
2024-11-26 07:07:00 -05:00
parent 0f8a4e0027
commit 0253a76dbe
4 changed files with 226 additions and 40 deletions
+6 -2
View File
@@ -65,7 +65,9 @@ func TestReader(t *testing.T) {
os.RemoveAll(path)
os.MkdirAll(path, 0777)
err = extractToDir(rdr, &rdr.Root.FileBase, path)
t.Fatal(err)
if err != nil {
t.Fatal(err)
}
}
var singleFile = "PortableApps/CPU-X/CPU-X-v4.2.0-x86_64.AppImage"
@@ -89,7 +91,9 @@ func TestSingleFile(t *testing.T) {
t.Fatal(err)
}
err = extractToDir(rdr, &b, path)
t.Fatal(err)
if err != nil {
t.Fatal(err)
}
}
func extractToDir(rdr *squashfslow.Reader, b *squashfslow.FileBase, folder string) error {