#492: Now correctly parses multiple strings for ASCII fields.

(cherry picked from commit 8247861095c5980ca3dbc278fd775ce6fc4de070)
This commit is contained in:
Harald Kuhr 2019-08-08 23:03:13 +02:00
parent 0e41d4a5f7
commit bdd7f5b228

View File

@ -395,10 +395,16 @@ public final class TIFFReader extends MetadataReader {
if (pCount == 0) {
return "";
}
// NOTE: This can actually be more than one string, each string ends with a NULL-terminator
byte[] ascii = new byte[pCount];
pInput.readFully(ascii);
int len = ascii[ascii.length - 1] == 0 ? ascii.length - 1 : ascii.length;
return StringUtil.decode(ascii, 0, len, "UTF-8"); // UTF-8 is ASCII compatible
String[] strings = new String(ascii, 0, len, StandardCharsets.UTF_8) // UTF-8 is ASCII compatible
.split("\0"); // Split on NULL
return strings.length == 1 ? strings[0] : strings;
case TIFF.TYPE_BYTE:
if (pCount == 1) {
return pInput.readUnsignedByte();