Skip to content

Commit

Permalink
Handle ID3 frames that end with empty text field
Browse files Browse the repository at this point in the history
Issue: #2309

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144061654
  • Loading branch information
ojw28 committed Jan 10, 2017
1 parent bf65df1 commit deefe50
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,14 @@ private static TxxxFrame decodeTxxxFrame(ParsableByteArray id3Data, int frameSiz
int descriptionEndIndex = indexOfEos(data, 0, encoding);
String description = new String(data, 0, descriptionEndIndex, charset);

String value;
int valueStartIndex = descriptionEndIndex + delimiterLength(encoding);
int valueEndIndex = indexOfEos(data, valueStartIndex, encoding);
String value = new String(data, valueStartIndex, valueEndIndex - valueStartIndex, charset);
if (valueStartIndex < data.length) {
int valueEndIndex = indexOfEos(data, valueStartIndex, encoding);
value = new String(data, valueStartIndex, valueEndIndex - valueStartIndex, charset);
} else {
value = "";
}

return new TxxxFrame(description, value);
}
Expand Down Expand Up @@ -408,15 +413,25 @@ private static CommentFrame decodeCommentFrame(ParsableByteArray id3Data, int fr
int descriptionEndIndex = indexOfEos(data, 0, encoding);
String description = new String(data, 0, descriptionEndIndex, charset);

String text;
int textStartIndex = descriptionEndIndex + delimiterLength(encoding);
int textEndIndex = indexOfEos(data, textStartIndex, encoding);
String text = new String(data, textStartIndex, textEndIndex - textStartIndex, charset);
if (textStartIndex < data.length) {
int textEndIndex = indexOfEos(data, textStartIndex, encoding);
text = new String(data, textStartIndex, textEndIndex - textStartIndex, charset);
} else {
text = "";
}

return new CommentFrame(language, description, text);
}

private static TextInformationFrame decodeTextInformationFrame(ParsableByteArray id3Data,
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();
String charset = getCharsetName(encoding);

Expand Down

0 comments on commit deefe50

Please sign in to comment.