}
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]
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
}
return out
}
-func NewFlattenedFileObject(fileRoot string, filePath, fileName []byte) (*flattenedFileObject, error) {
+func NewFlattenedFileObject(fileRoot string, filePath, fileName []byte, dataOffset int64) (*flattenedFileObject, error) {
fullFilePath, err := readPath(fileRoot, filePath, fileName)
if err != nil {
return nil, err
}
- file, err := os.Open(fullFilePath)
+ file, err := effectiveFile(fullFilePath)
if err != nil {
return nil, err
}
+
defer func(file *os.File) { _ = file.Close() }(file)
fileInfo, err := file.Stat()
}
dataSize := make([]byte, 4)
- binary.BigEndian.PutUint32(dataSize, uint32(fileInfo.Size()))
+ binary.BigEndian.PutUint32(dataSize, uint32(fileInfo.Size()-dataOffset))
mTime := toHotlineTime(fileInfo.ModTime())