diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-05 12:00:02 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-05 12:00:02 -0700 |
| commit | 050407a3b7f719ed6ce9367eb803bf948075e50e (patch) | |
| tree | 4edf660e513c961e6836f119359f83c1f52ebb06 /hotline/flattened_file_object.go | |
| parent | 4c24568a917fb84c429411f12e096a64222a1566 (diff) | |
Handle zero length comment and file paths for Nostalgia compatibility
Diffstat (limited to 'hotline/flattened_file_object.go')
| -rw-r--r-- | hotline/flattened_file_object.go | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/hotline/flattened_file_object.go b/hotline/flattened_file_object.go index 6f38e46..a43677b 100644 --- a/hotline/flattened_file_object.go +++ b/hotline/flattened_file_object.go @@ -110,20 +110,10 @@ type FlatFileDataForkHeader struct { } func (ffif *FlatFileInformationFork) UnmarshalBinary(b []byte) error { - nameSize := b[70:72] bs := binary.BigEndian.Uint16(nameSize) - nameEnd := 72 + bs - commentSize := b[nameEnd : nameEnd+2] - commentLen := binary.BigEndian.Uint16(commentSize) - - commentStartPos := int(nameEnd) + 2 - commentEndPos := int(nameEnd) + 2 + int(commentLen) - - comment := b[commentStartPos:commentEndPos] - ffif.Platform = b[0:4] ffif.TypeSignature = b[4:8] ffif.CreatorSignature = b[8:12] @@ -135,8 +125,16 @@ func (ffif *FlatFileInformationFork) UnmarshalBinary(b []byte) error { ffif.NameScript = b[68:70] ffif.NameSize = b[70:72] ffif.Name = b[72:nameEnd] - ffif.CommentSize = b[nameEnd : nameEnd+2] - ffif.Comment = comment + + if len(b) > int(nameEnd) { + ffif.CommentSize = b[nameEnd : nameEnd+2] + commentLen := binary.BigEndian.Uint16(ffif.CommentSize) + + commentStartPos := int(nameEnd) + 2 + commentEndPos := int(nameEnd) + 2 + int(commentLen) + + ffif.Comment = b[commentStartPos:commentEndPos] + } return nil } |