Skip to content

Commit 0ab0fa9

Browse files
aarzillikdomanski
authored andcommitted
Use uint32 to decode directory entry length
Use unsigned integers for the ExtentLength field of directory entries.
1 parent aa2cb38 commit 0ab0fa9

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

image_writer.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ func manglePath(input string) (string, string) {
165165
// @param {string} givenPath Path to convert
166166
//
167167
// @returns {string} Converted filepath
168-
//
169168
func posixifyPath(path string) string {
170169
if runtime.GOOS == "windows" {
171170
return strings.ReplaceAll(path, "\\", "/")
@@ -297,7 +296,7 @@ func (wc *writeContext) createDEForRoot() (*DirectoryEntry, error) {
297296
de := &DirectoryEntry{
298297
ExtendedAtributeRecordLength: 0,
299298
ExtentLocation: int32(extentLocation),
300-
ExtentLength: int32(extentLengthInSectors * sectorSize),
299+
ExtentLength: uint32(extentLengthInSectors * sectorSize),
301300
RecordingDateTime: wc.timestamp,
302301
FileFlags: dirFlagDir,
303302
FileUnitSize: 0, // 0 for non-interleaved write
@@ -355,7 +354,7 @@ func (wc *writeContext) scanDirectory(item *itemToWrite, dirPath string, ownEntr
355354
de := &DirectoryEntry{
356355
ExtendedAtributeRecordLength: 0,
357356
ExtentLocation: int32(extentLocation),
358-
ExtentLength: int32(extentLength),
357+
ExtentLength: uint32(extentLength),
359358
RecordingDateTime: wc.timestamp,
360359
FileFlags: fileFlags,
361360
FileUnitSize: 0, // 0 for non-interleaved write

iso9660.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ var _ encoding.BinaryMarshaler = PrimaryVolumeDescriptorBody{}
127127
type DirectoryEntry struct {
128128
ExtendedAtributeRecordLength byte
129129
ExtentLocation int32
130-
ExtentLength int32
130+
ExtentLength uint32
131131
RecordingDateTime RecordingTimestamp
132132
FileFlags byte
133133
FileUnitSize byte
@@ -155,7 +155,7 @@ func (de *DirectoryEntry) UnmarshalBinary(data []byte) error {
155155
return err
156156
}
157157

158-
if de.ExtentLength, err = UnmarshalInt32LSBMSB(data[10:18]); err != nil {
158+
if de.ExtentLength, err = UnmarshalUint32LSBMSB(data[10:18]); err != nil {
159159
return err
160160
}
161161

@@ -196,7 +196,7 @@ func (de *DirectoryEntry) MarshalBinary() ([]byte, error) {
196196
data[1] = de.ExtendedAtributeRecordLength
197197

198198
WriteInt32LSBMSB(data[2:10], de.ExtentLocation)
199-
WriteInt32LSBMSB(data[10:18], de.ExtentLength)
199+
WriteInt32LSBMSB(data[10:18], int32(de.ExtentLength))
200200
de.RecordingDateTime.MarshalBinary(data[18:25])
201201
data[25] = de.FileFlags
202202
data[26] = de.FileUnitSize

iso9660_datatypes.go

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func UnmarshalInt32LSBMSB(data []byte) (int32, error) {
3333
return lsb, nil
3434
}
3535

36+
// UnmarshalUint32LSBMSB is the same as UnmarshalInt32LSBMSB but returns an unsigned integer
37+
func UnmarshalUint32LSBMSB(data []byte) (uint32, error) {
38+
n, err := UnmarshalInt32LSBMSB(data)
39+
return uint32(n), err
40+
}
41+
3642
// UnmarshalInt16LSBMSB decodes a 16-bit integer in both byte orders, as defined in ECMA-119 7.3.3
3743
func UnmarshalInt16LSBMSB(data []byte) (int16, error) {
3844
if len(data) < 4 {

0 commit comments

Comments
 (0)