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
committed by Caleb Gardner
parent 81b663b48a
commit 0905141013
4 changed files with 228 additions and 40 deletions
+8 -4
View File
@@ -77,8 +77,10 @@ func TestReader(t *testing.T) {
path := filepath.Join(tmpDir, "extractTest")
os.RemoveAll(path)
os.MkdirAll(path, 0777)
err = extractToDir(rdr, rdr.Root.FileBase, path)
t.Fatal(err)
err = extractToDir(rdr, &rdr.Root.FileBase, path)
if err != nil {
t.Fatal(err)
}
}
var singleFile = "PortableApps/CPU-X/CPU-X-v4.2.0-x86_64.AppImage"
@@ -101,8 +103,10 @@ func TestSingleFile(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = extractToDir(rdr, b, path)
t.Fatal(err)
err = extractToDir(rdr, &b, path)
if err != nil {
t.Fatal(err)
}
}
func extractToDir(rdr Reader, b FileBase, folder string) error {