Skip to content

Commit

Permalink
Use uint32 to decode directory entry length
Browse files Browse the repository at this point in the history
Use unsigned integers for the ExtentLength field of directory entries.
  • Loading branch information
aarzilli authored and kdomanski committed Aug 26, 2022
1 parent aa2cb38 commit 0ab0fa9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 2 additions & 3 deletions image_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func manglePath(input string) (string, string) {
// @param {string} givenPath Path to convert
//
// @returns {string} Converted filepath
//
func posixifyPath(path string) string {
if runtime.GOOS == "windows" {
return strings.ReplaceAll(path, "\\", "/")
Expand Down Expand Up @@ -297,7 +296,7 @@ func (wc *writeContext) createDEForRoot() (*DirectoryEntry, error) {
de := &DirectoryEntry{
ExtendedAtributeRecordLength: 0,
ExtentLocation: int32(extentLocation),
ExtentLength: int32(extentLengthInSectors * sectorSize),
ExtentLength: uint32(extentLengthInSectors * sectorSize),
RecordingDateTime: wc.timestamp,
FileFlags: dirFlagDir,
FileUnitSize: 0, // 0 for non-interleaved write
Expand Down Expand Up @@ -355,7 +354,7 @@ func (wc *writeContext) scanDirectory(item *itemToWrite, dirPath string, ownEntr
de := &DirectoryEntry{
ExtendedAtributeRecordLength: 0,
ExtentLocation: int32(extentLocation),
ExtentLength: int32(extentLength),
ExtentLength: uint32(extentLength),
RecordingDateTime: wc.timestamp,
FileFlags: fileFlags,
FileUnitSize: 0, // 0 for non-interleaved write
Expand Down
6 changes: 3 additions & 3 deletions iso9660.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var _ encoding.BinaryMarshaler = PrimaryVolumeDescriptorBody{}
type DirectoryEntry struct {
ExtendedAtributeRecordLength byte
ExtentLocation int32
ExtentLength int32
ExtentLength uint32
RecordingDateTime RecordingTimestamp
FileFlags byte
FileUnitSize byte
Expand Down Expand Up @@ -155,7 +155,7 @@ func (de *DirectoryEntry) UnmarshalBinary(data []byte) error {
return err
}

if de.ExtentLength, err = UnmarshalInt32LSBMSB(data[10:18]); err != nil {
if de.ExtentLength, err = UnmarshalUint32LSBMSB(data[10:18]); err != nil {
return err
}

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

WriteInt32LSBMSB(data[2:10], de.ExtentLocation)
WriteInt32LSBMSB(data[10:18], de.ExtentLength)
WriteInt32LSBMSB(data[10:18], int32(de.ExtentLength))
de.RecordingDateTime.MarshalBinary(data[18:25])
data[25] = de.FileFlags
data[26] = de.FileUnitSize
Expand Down
6 changes: 6 additions & 0 deletions iso9660_datatypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func UnmarshalInt32LSBMSB(data []byte) (int32, error) {
return lsb, nil
}

// UnmarshalUint32LSBMSB is the same as UnmarshalInt32LSBMSB but returns an unsigned integer
func UnmarshalUint32LSBMSB(data []byte) (uint32, error) {
n, err := UnmarshalInt32LSBMSB(data)
return uint32(n), err
}

// UnmarshalInt16LSBMSB decodes a 16-bit integer in both byte orders, as defined in ECMA-119 7.3.3
func UnmarshalInt16LSBMSB(data []byte) (int16, error) {
if len(data) < 4 {
Expand Down

0 comments on commit 0ab0fa9

Please sign in to comment.