Skip to content

Commit 6f00aba

Browse files
committedAug 23, 2024··
fix: check descriptor capacity during SIF creation
1 parent c1fcc37 commit 6f00aba

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎pkg/sif/create.go

+8
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,16 @@ func OptCreateWithCloseOnUnload(b bool) CreateOpt {
233233
}
234234
}
235235

236+
var errDescriptorCapacityNotSupported = errors.New("descriptor capacity not supported")
237+
236238
// createContainer creates a new SIF container file in rw, according to opts.
237239
func createContainer(rw ReadWriter, co createOpts) (*FileImage, error) {
240+
// The supported number of descriptors is limited by the unsigned 32-bit ID field in each
241+
// rawDescriptor.
242+
if co.descriptorCapacity >= math.MaxUint32 {
243+
return nil, errDescriptorCapacityNotSupported
244+
}
245+
238246
rds := make([]rawDescriptor, co.descriptorCapacity)
239247
rdsSize := int64(binary.Size(rds))
240248

‎pkg/sif/create_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ func TestCreateContainerAtPath(t *testing.T) {
186186
opts []CreateOpt
187187
wantErr error
188188
}{
189+
{
190+
name: "ErrDescriptorCapacityNotSupported",
191+
opts: []CreateOpt{
192+
OptCreateWithDescriptorCapacity(math.MaxUint32),
193+
},
194+
wantErr: errDescriptorCapacityNotSupported,
195+
},
189196
{
190197
name: "ErrInsufficientCapacity",
191198
opts: []CreateOpt{

0 commit comments

Comments
 (0)
Please sign in to comment.