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:
+6
-2
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user