Skip to content

Commit 7d7a089

Browse files
committed
return more specific error message when attemting to decode UDF volume
1 parent 819be47 commit 7d7a089

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

iso9660.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
sectorSize uint32 = 2048
2020
systemAreaSize = sectorSize * 16
2121
standardIdentifier = "CD001"
22+
udfIdentifier = "BEA01"
2223

2324
volumeTypeBoot byte = 0
2425
volumeTypePrimary byte = 1
@@ -48,6 +49,8 @@ const (
4849

4950
var standardIdentifierBytes = [5]byte{'C', 'D', '0', '0', '1'}
5051

52+
var ErrUDFNotSupported = errors.New("UDF volumes are not supported")
53+
5154
// volumeDescriptorHeader represents the data in bytes 0-6
5255
// of a Volume Descriptor as defined in ECMA-119 8.1
5356
type volumeDescriptorHeader struct {
@@ -404,8 +407,12 @@ func (vd *volumeDescriptor) UnmarshalBinary(data []byte) error {
404407
return err
405408
}
406409

407-
if string(vd.Header.Identifier[:]) != standardIdentifier {
408-
return fmt.Errorf("volume descriptor %q != %q", string(vd.Header.Identifier[:]), standardIdentifier)
410+
id := string(vd.Header.Identifier[:])
411+
if id != standardIdentifier {
412+
if id == udfIdentifier {
413+
return ErrUDFNotSupported
414+
}
415+
return fmt.Errorf("volume descriptor %q != %q", id, standardIdentifier)
409416
}
410417

411418
switch vd.Header.Type {

iso9660_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ func TestIncorrectData(t *testing.T) {
126126
assert.ErrorIs(tt, err, io.ErrUnexpectedEOF)
127127
})
128128

129+
t.Run("volumeDescriptor is UDF", func(tt *testing.T) {
130+
vd := &volumeDescriptor{}
131+
data := make([]byte, sectorSize)
132+
copy(data[1:6], []byte(udfIdentifier))
133+
err := vd.UnmarshalBinary(data)
134+
assert.Equal(tt, ErrUDFNotSupported, err)
135+
})
136+
129137
t.Run("volumeDescriptor has invalid volume type", func(tt *testing.T) {
130138
vd := &volumeDescriptor{}
131139
data := make([]byte, sectorSize)

0 commit comments

Comments
 (0)