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 #55
pull/69/head
Dustin Oprea 2021-05-12 00:32:26 -04:00
parent cb1753e83a
commit 120bcdb2a5
1 changed files with 6 additions and 3 deletions

View File

@ -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
}
}