Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix font name field parsing of QuicktimeText block #470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class QuicktimeTextSampleEntry extends AbstractSampleEntry {
int foregroundB = 65535;

String fontName = "";
boolean rawFontName; // Is fontName in raw format or in pascal-string format.
int dataReferenceIndex;

public QuicktimeTextSampleEntry() {
Expand Down Expand Up @@ -85,6 +86,11 @@ public void parse(ReadableByteChannel dataSource, ByteBuffer header, long conten
foregroundB = IsoTypeReader.readUInt16(content);
if (content.remaining() > 0) {
int length = IsoTypeReader.readUInt8(content);
if (length != content.remaining()) {
content.position(content.position() - 1);
length = content.remaining();
rawFontName = true;
}
byte[] myFontName = new byte[length];
content.get(myFontName);
fontName = new String(myFontName);
Expand All @@ -108,7 +114,8 @@ public void addBox(Box box) {
public void getBox(WritableByteChannel writableByteChannel) throws IOException {
writableByteChannel.write(getHeader());

ByteBuffer byteBuffer = ByteBuffer.allocate(52 + (fontName != null ? fontName.length() : 0));
ByteBuffer byteBuffer = ByteBuffer.allocate(51 + (rawFontName ? 0 : 1) +
(fontName != null ? fontName.length() : 0));
((Buffer)byteBuffer).position(6);
IsoTypeWriter.writeUInt16(byteBuffer, dataReferenceIndex);
byteBuffer.putInt(displayFlags);
Expand All @@ -127,16 +134,21 @@ public void getBox(WritableByteChannel writableByteChannel) throws IOException {
IsoTypeWriter.writeUInt16(byteBuffer, foregroundG);
IsoTypeWriter.writeUInt16(byteBuffer, foregroundB);
if (fontName != null) {
IsoTypeWriter.writeUInt8(byteBuffer, fontName.length());
byteBuffer.put(fontName.getBytes());
if (rawFontName) {
byteBuffer.put(fontName.getBytes());
}
else {
IsoTypeWriter.writeUInt8(byteBuffer, fontName.length());
byteBuffer.put(fontName.getBytes());
}
}
writableByteChannel.write((ByteBuffer) ((Buffer)byteBuffer).rewind());
// writeContainer(writableByteChannel); there are no child boxes!?
}

@Override
public long getSize() {
long s = getContainerSize() + 52 + (fontName != null ? fontName.length() : 0);
long s = getContainerSize() + 51 + (rawFontName ? 0 : 1) + (fontName != null ? fontName.length() : 0);
s += ((largeBox || (s + 8) >= (1L << 32)) ? 16 : 8);
return s;
}
Expand Down