Skip to content

Commit

Permalink
fix: check descriptor capacity during SIF creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tri-adam committed Aug 23, 2024
1 parent 390d447 commit 9d13b4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/sif/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,16 @@ func OptCreateWithCloseOnUnload(b bool) CreateOpt {
}
}

var errDescriptorCapacityNotSupported = errors.New("descriptor capacity not supported")

// createContainer creates a new SIF container file in rw, according to opts.
func createContainer(rw ReadWriter, co createOpts) (*FileImage, error) {
// The supported number of descriptors is limited by the unsigned 32-bit ID field in each
// rawDescriptor.
if co.descriptorCapacity >= math.MaxUint32 {
return nil, errDescriptorCapacityNotSupported
}

rds := make([]rawDescriptor, co.descriptorCapacity)
rdsSize := int64(binary.Size(rds))

Expand Down
7 changes: 7 additions & 0 deletions pkg/sif/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ func TestCreateContainerAtPath(t *testing.T) {
opts []CreateOpt
wantErr error
}{
{
name: "ErrDescriptorCapacityNotSupported",
opts: []CreateOpt{
OptCreateWithDescriptorCapacity(math.MaxUint32),
},
wantErr: errDescriptorCapacityNotSupported,
},
{
name: "ErrInsufficientCapacity",
opts: []CreateOpt{
Expand Down

0 comments on commit 9d13b4d

Please sign in to comment.