mirror of https://github.com/dsoprea/go-exif.git
common/parser.go: Trim ASCII-NUL strings to exclude binary characters
This is for convenience. We're already ignoring whether it does or does not have the NUL. Since having binary characters is likely an undesireable flaw in the image and support for binary characters by EXIF is probably just a vestigial, ridiculous feature, just stop short and return the preceding characters if encountered. If we do actually need the binary at some point in the future, we can circle back and potentially add an option to do so. Closes #55pull/69/head
parent
cb1753e83a
commit
120bcdb2a5
|
@ -62,13 +62,16 @@ func (p *Parser) ParseAscii(data []byte, unitCount uint32) (value string, err er
|
|||
|
||||
if len(data) == 0 || data[count-1] != 0 {
|
||||
s := string(data[:count])
|
||||
parserLogger.Warningf(nil, "ascii not terminated with nul as expected: [%v]", s)
|
||||
parserLogger.Warningf(nil, "ASCII not terminated with NUL as expected: [%v]", s)
|
||||
|
||||
for _, c := range s {
|
||||
for i, c := range s {
|
||||
if c > 127 {
|
||||
// Binary
|
||||
|
||||
return "", ErrParseFail
|
||||
t := s[:i]
|
||||
parserLogger.Warningf(nil, "ASCII also had binary characters. Truncating: [%v]->[%s]", s, t)
|
||||
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue