Skip to content

Commit

Permalink
return more specific error message when attemting to decode UDF volume
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomanski committed May 1, 2023
1 parent 819be47 commit 7d7a089
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions iso9660.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
sectorSize uint32 = 2048
systemAreaSize = sectorSize * 16
standardIdentifier = "CD001"
udfIdentifier = "BEA01"

volumeTypeBoot byte = 0
volumeTypePrimary byte = 1
Expand Down Expand Up @@ -48,6 +49,8 @@ const (

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

var ErrUDFNotSupported = errors.New("UDF volumes are not supported")

// volumeDescriptorHeader represents the data in bytes 0-6
// of a Volume Descriptor as defined in ECMA-119 8.1
type volumeDescriptorHeader struct {
Expand Down Expand Up @@ -404,8 +407,12 @@ func (vd *volumeDescriptor) UnmarshalBinary(data []byte) error {
return err
}

if string(vd.Header.Identifier[:]) != standardIdentifier {
return fmt.Errorf("volume descriptor %q != %q", string(vd.Header.Identifier[:]), standardIdentifier)
id := string(vd.Header.Identifier[:])
if id != standardIdentifier {
if id == udfIdentifier {
return ErrUDFNotSupported
}
return fmt.Errorf("volume descriptor %q != %q", id, standardIdentifier)
}

switch vd.Header.Type {
Expand Down
8 changes: 8 additions & 0 deletions iso9660_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ func TestIncorrectData(t *testing.T) {
assert.ErrorIs(tt, err, io.ErrUnexpectedEOF)
})

t.Run("volumeDescriptor is UDF", func(tt *testing.T) {
vd := &volumeDescriptor{}
data := make([]byte, sectorSize)
copy(data[1:6], []byte(udfIdentifier))
err := vd.UnmarshalBinary(data)
assert.Equal(tt, ErrUDFNotSupported, err)
})

t.Run("volumeDescriptor has invalid volume type", func(tt *testing.T) {
vd := &volumeDescriptor{}
data := make([]byte, sectorSize)
Expand Down

0 comments on commit 7d7a089

Please sign in to comment.