diff options
Diffstat (limited to 'objectstore/packed')
| -rw-r--r-- | objectstore/packed/delta_plan.go | 4 | ||||
| -rw-r--r-- | objectstore/packed/entry_parse.go | 10 | ||||
| -rw-r--r-- | objectstore/packed/idx_load.go | 8 | ||||
| -rw-r--r-- | objectstore/packed/idx_parse.go | 5 | ||||
| -rw-r--r-- | objectstore/packed/pack.go | 8 | ||||
| -rw-r--r-- | objectstore/packed/read_test.go | 9 |
6 files changed, 34 insertions, 10 deletions
diff --git a/objectstore/packed/delta_plan.go b/objectstore/packed/delta_plan.go index e55400aa..5a989c62 100644 --- a/objectstore/packed/delta_plan.go +++ b/objectstore/packed/delta_plan.go @@ -74,6 +74,10 @@ func (store *Store) deltaPlanFor(start location) (deltaPlan, error) { packName: current.packName, offset: meta.baseOfs, } + case objecttype.TypeCommit, objecttype.TypeTree, objecttype.TypeBlob, objecttype.TypeTag: + return deltaPlan{}, fmt.Errorf("objectstore/packed: internal invariant violation for base type %d", meta.ty) + case objecttype.TypeInvalid, objecttype.TypeFuture: + return deltaPlan{}, fmt.Errorf("objectstore/packed: unsupported pack type %d", meta.ty) default: return deltaPlan{}, fmt.Errorf("objectstore/packed: unsupported pack type %d", meta.ty) } diff --git a/objectstore/packed/entry_parse.go b/objectstore/packed/entry_parse.go index e3cbeac3..76fcb754 100644 --- a/objectstore/packed/entry_parse.go +++ b/objectstore/packed/entry_parse.go @@ -3,6 +3,7 @@ package packed import ( "fmt" + "codeberg.org/lindenii/furgit/internal/intconv" "codeberg.org/lindenii/furgit/objectid" "codeberg.org/lindenii/furgit/objecttype" ) @@ -28,7 +29,10 @@ func parseEntryMeta(pack *packFile, algo objectid.Algorithm, offset uint64) (ent return zero, fmt.Errorf("objectstore/packed: pack %q offset %d out of bounds", pack.name, offset) } - pos := int(offset) + pos, err := intconv.Uint64ToInt(offset) + if err != nil { + return zero, fmt.Errorf("objectstore/packed: pack %q offset conversion: %w", pack.name, err) + } first := pack.data[pos] pos++ @@ -76,6 +80,8 @@ func parseEntryMeta(pack *packFile, algo objectid.Algorithm, offset uint64) (ent return zero, fmt.Errorf("objectstore/packed: pack %q has invalid ofs-delta base", pack.name) } meta.baseOfs = offset - dist + case objecttype.TypeInvalid, objecttype.TypeFuture: + return zero, fmt.Errorf("objectstore/packed: pack %q has unsupported object type %d", pack.name, meta.ty) default: return zero, fmt.Errorf("objectstore/packed: pack %q has unsupported object type %d", pack.name, meta.ty) } @@ -111,6 +117,8 @@ func isBaseObjectType(ty objecttype.Type) bool { switch ty { case objecttype.TypeCommit, objecttype.TypeTree, objecttype.TypeBlob, objecttype.TypeTag: return true + case objecttype.TypeInvalid, objecttype.TypeFuture, objecttype.TypeOfsDelta, objecttype.TypeRefDelta: + return false default: return false } diff --git a/objectstore/packed/idx_load.go b/objectstore/packed/idx_load.go index 106701fd..293e005f 100644 --- a/objectstore/packed/idx_load.go +++ b/objectstore/packed/idx_load.go @@ -7,6 +7,7 @@ import ( "strings" "syscall" + "codeberg.org/lindenii/furgit/internal/intconv" "codeberg.org/lindenii/furgit/objectid" ) @@ -106,7 +107,12 @@ func openIdxFile(root *os.Root, idxName, packName string, algo objectid.Algorith _ = file.Close() return nil, fmt.Errorf("objectstore/packed: idx %q has unsupported size", idxName) } - data, err := syscall.Mmap(int(file.Fd()), 0, int(size), syscall.PROT_READ, syscall.MAP_PRIVATE) + fd, err := intconv.UintptrToInt(file.Fd()) + if err != nil { + _ = file.Close() + return nil, err + } + data, err := syscall.Mmap(fd, 0, int(size), syscall.PROT_READ, syscall.MAP_PRIVATE) if err != nil { _ = file.Close() return nil, err diff --git a/objectstore/packed/idx_parse.go b/objectstore/packed/idx_parse.go index a6adc721..0af72594 100644 --- a/objectstore/packed/idx_parse.go +++ b/objectstore/packed/idx_parse.go @@ -62,10 +62,7 @@ func (index *idxFile) parse() error { return fmt.Errorf("objectstore/packed: idx %q has malformed 64-bit offset table", index.idxName) } index.offset64Count = offset64Bytes / 8 - maxOffset64Count := index.numObjects - 1 - if maxOffset64Count < 0 { - maxOffset64Count = 0 - } + maxOffset64Count := max(index.numObjects-1, 0) if index.offset64Count > maxOffset64Count { return fmt.Errorf("objectstore/packed: idx %q has oversized 64-bit offset table", index.idxName) } diff --git a/objectstore/packed/pack.go b/objectstore/packed/pack.go index 46eca524..00950159 100644 --- a/objectstore/packed/pack.go +++ b/objectstore/packed/pack.go @@ -5,6 +5,8 @@ import ( "fmt" "os" "syscall" + + "codeberg.org/lindenii/furgit/internal/intconv" ) const packSignature = 0x5041434b @@ -27,7 +29,11 @@ func openPackFile(name string, file *os.File, size int64) (*packFile, error) { if size > int64(int(^uint(0)>>1)) { return nil, fmt.Errorf("objectstore/packed: pack %q has unsupported size", name) } - data, err := syscall.Mmap(int(file.Fd()), 0, int(size), syscall.PROT_READ, syscall.MAP_PRIVATE) + fd, err := intconv.UintptrToInt(file.Fd()) + if err != nil { + return nil, err + } + data, err := syscall.Mmap(fd, 0, int(size), syscall.PROT_READ, syscall.MAP_PRIVATE) if err != nil { return nil, err } diff --git a/objectstore/packed/read_test.go b/objectstore/packed/read_test.go index 0eb78366..9a7f2e4a 100644 --- a/objectstore/packed/read_test.go +++ b/objectstore/packed/read_test.go @@ -14,12 +14,12 @@ import ( ) func TestPackedStoreReadAgainstGit(t *testing.T) { - testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { + t.Parallel() + testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper testRepo, ids := createPackedFixtureRepo(t, algo) store := openPackedStore(t, testRepo.Dir(), algo) for _, id := range ids { - id := id t.Run(id.String(), func(t *testing.T) { wantType, wantBody, wantRaw := expectedRawObject(t, testRepo, id) @@ -80,7 +80,8 @@ func TestPackedStoreReadAgainstGit(t *testing.T) { } func TestPackedStoreErrors(t *testing.T) { - testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { + t.Parallel() + testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper testRepo, _ := createPackedFixtureRepo(t, algo) store := openPackedStore(t, testRepo.Dir(), algo) @@ -125,6 +126,7 @@ func TestPackedStoreErrors(t *testing.T) { } func TestPackedStoreNewValidation(t *testing.T) { + t.Parallel() testRepo, _ := createPackedFixtureRepo(t, objectid.AlgorithmSHA1) store := openPackedStore(t, testRepo.Dir(), objectid.AlgorithmSHA1) if err := store.Close(); err != nil { @@ -136,6 +138,7 @@ func TestPackedStoreNewValidation(t *testing.T) { } func TestPackedStoreInvalidAlgorithm(t *testing.T) { + t.Parallel() testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: objectid.AlgorithmSHA1, Bare: true}) root, err := os.OpenRoot(testRepo.Dir()) if err != nil { |
