Commit deefe50a by olly Committed by Oliver Woodman

Handle ID3 frames that end with empty text field

Issue: #2309

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144061654
parent bf65df1b
...@@ -308,9 +308,14 @@ public final class Id3Decoder implements MetadataDecoder { ...@@ -308,9 +308,14 @@ public final class Id3Decoder implements MetadataDecoder {
int descriptionEndIndex = indexOfEos(data, 0, encoding); int descriptionEndIndex = indexOfEos(data, 0, encoding);
String description = new String(data, 0, descriptionEndIndex, charset); String description = new String(data, 0, descriptionEndIndex, charset);
String value;
int valueStartIndex = descriptionEndIndex + delimiterLength(encoding); int valueStartIndex = descriptionEndIndex + delimiterLength(encoding);
int valueEndIndex = indexOfEos(data, valueStartIndex, encoding); if (valueStartIndex < data.length) {
String value = new String(data, valueStartIndex, valueEndIndex - valueStartIndex, charset); int valueEndIndex = indexOfEos(data, valueStartIndex, encoding);
value = new String(data, valueStartIndex, valueEndIndex - valueStartIndex, charset);
} else {
value = "";
}
return new TxxxFrame(description, value); return new TxxxFrame(description, value);
} }
...@@ -408,15 +413,25 @@ public final class Id3Decoder implements MetadataDecoder { ...@@ -408,15 +413,25 @@ public final class Id3Decoder implements MetadataDecoder {
int descriptionEndIndex = indexOfEos(data, 0, encoding); int descriptionEndIndex = indexOfEos(data, 0, encoding);
String description = new String(data, 0, descriptionEndIndex, charset); String description = new String(data, 0, descriptionEndIndex, charset);
String text;
int textStartIndex = descriptionEndIndex + delimiterLength(encoding); int textStartIndex = descriptionEndIndex + delimiterLength(encoding);
int textEndIndex = indexOfEos(data, textStartIndex, encoding); if (textStartIndex < data.length) {
String text = new String(data, textStartIndex, textEndIndex - textStartIndex, charset); int textEndIndex = indexOfEos(data, textStartIndex, encoding);
text = new String(data, textStartIndex, textEndIndex - textStartIndex, charset);
} else {
text = "";
}
return new CommentFrame(language, description, text); return new CommentFrame(language, description, text);
} }
private static TextInformationFrame decodeTextInformationFrame(ParsableByteArray id3Data, private static TextInformationFrame decodeTextInformationFrame(ParsableByteArray id3Data,
int frameSize, String id) throws UnsupportedEncodingException { int frameSize, String id) throws UnsupportedEncodingException {
if (frameSize <= 1) {
// Frame is empty or contains only the text encoding byte.
return new TextInformationFrame(id, "");
}
int encoding = id3Data.readUnsignedByte(); int encoding = id3Data.readUnsignedByte();
String charset = getCharsetName(encoding); String charset = getCharsetName(encoding);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment