diff --git a/iso9660.go b/iso9660.go index abc18e1..2b2e67c 100644 --- a/iso9660.go +++ b/iso9660.go @@ -19,6 +19,7 @@ const ( sectorSize uint32 = 2048 systemAreaSize = sectorSize * 16 standardIdentifier = "CD001" + udfIdentifier = "BEA01" volumeTypeBoot byte = 0 volumeTypePrimary byte = 1 @@ -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 { @@ -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 { diff --git a/iso9660_test.go b/iso9660_test.go index 428fc91..f04706f 100644 --- a/iso9660_test.go +++ b/iso9660_test.go @@ -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)