Skip to main content
Participant
May 13, 2008 8:35 AM UTC
Question

DefineFont2/3 tag parsing bug

mxmlc report a "Unable to create source" error when I tried to<br />embed a swf file into flex application.<br /><br />Following is the stacktrace for this error.<br /><br />java.lang.StringIndexOutOfBoundsException: String index out of range: -1<br /> at java.lang.String.checkBounds(String.java:405)<br /> at java.lang.String.<init>(String.java:450)<br /> at flash.swf.SwfDecoder.readLengthString(SwfDecoder.java:275)<br /> at flash.swf.TagDecoder.decodeDefineFont2And3(TagDecoder.java:770)<br /> at flash.swf.TagDecoder.decodeDefineFont2(TagDecoder.java:737)<br /> ...<br /><br />I think this problem because of swfdecoder parsing font name wrong way.<br /><br />DefineFontInfo tag description in swf file format spec says,<br /> Note that font name strings in the DefineFontInfo tag are not null-terminated;<br /> instead their length is specified by the FontNameLen field.<br /><br />But SwfDecoder#readLengthString() try to remove null-terminator.<br /><br />Attached patch fix this problem.<br />Please entertain the patch.<br /><br />---<br />Sorry about my poor English.<br /><br />INADA Naoki <inada-n@klab.org><br /> K Laboratory, KLab Inc.
This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

Participating Frequently
May 21, 2008 1:18 PM UTC
Thanks Naoki,

I imagine swftools.org's library would need to detect and special case
non-null-terminated strings for this field to maintain backwards
compatibility.

Please note that the font name in the new SWF 9 DefineFontName tag is
different from the equivalent field in DefineFontInfo, DefineFont2 and
DefineFont3 in that the DefineFontName tags' font name field is not null
terminated.

Pete

________________________________

From: Naoki INADA [mailto:member@adobeforums.com]
Sent: Wednesday, May 21, 2008 2:44 AM
To: flexsdk-dev@adobeforums.com
Subject: Re: DefineFont2/3 tag parsing bug


A new message was posted by Naoki INADA in

Developers --
DefineFont2/3 tag parsing bug

Hi Peter.

The swf file that I encountered the crash was made by swftools
(http://www.swftools.org/) but not Flash or Flex.
I'll fix swftools.

Thank you a lot for your research.


________________________________

View/reply at DefineFont2/3 tag parsing bug

Replies by email are OK.
Use the unsubscribe
form
to cancel your email subscription.
Translate
Participant
May 21, 2008 5:44 AM UTC
Hi Peter.

The swf file that I encountered the crash was made by swftools (http://www.swftools.org/) but not Flash or Flex.
I'll fix swftools.

Thank you a lot for your research.
Translate
Participating Frequently
May 20, 2008 2:39 PM UTC
Hi Naoki,

Flex matches what Flash Authoring generates and it works in the player, so it is likely that the SWF specification is wrong. The fontName field for a DefineFontInfo or DefineFont2 or DefineFont3 tag is a null terminated String.

Pete
Translate
Participating Frequently
May 13, 2008 1:37 PM UTC
<DIV dir=ltr align=left><SPAN class=126172614-13052008><FONT face=Arial <br />color=#0000ff size=2>The code explicitly comments that removal of the null <br />terminator needs to be done, but as you said, this seems to contradict the <br />specification for fontName in DefineFontInfo or DefineFont2/3. Thankfully, <br />it seems readLengthString() is only used for font names.</FONT></SPAN></DIV><br /><DIV dir=ltr align=left><SPAN class=126172614-13052008><FONT face=Arial <br />color=#0000ff size=2></FONT></SPAN> </DIV><br /><DIV dir=ltr align=left><SPAN class=126172614-13052008><FONT face=Arial <br />color=#0000ff size=2>Before we change the code we'll ask the Flash team to <br />confirm whether the spec or our code is wrong. </FONT></SPAN><SPAN <br />class=126172614-13052008><FONT face=Arial color=#0000ff size=2>(However, from <br />the error message reported, it seems that an empty string (0 length) was <br />encountered for the font name and that seems invalid to <br />me...).</FONT></SPAN></DIV><br /><DIV dir=ltr align=left><SPAN class=126172614-13052008><FONT face=Arial <br />color=#0000ff size=2></FONT></SPAN> </DIV><br /><DIV dir=ltr align=left><SPAN class=126172614-13052008><FONT face=Arial <br />color=#0000ff size=2>Pete</FONT></SPAN></DIV>
Translate
Participant
May 13, 2008 8:48 AM UTC
Are attached files removed in this forum?

Following is the patch I attached previous message.

Index: modules/swfutils/src/java/flash/swf/SwfDecoder.java
===================================================================
--- modules/swfutils/src/java/flash/swf/SwfDecoder.java (revision 1678)
+++ modules/swfutils/src/java/flash/swf/SwfDecoder.java (working copy)
@@ -268,16 +268,15 @@
byte[] b = new byte[length];
readFully(b);

- // [paul] Flash Authoring and the player null terminate the
- // string, so ignore the last byte when constructing the String.
+ // In string with length, strings are not null-terminated.
if (swfVersion >= 6)
{
- return new String(b, 0, length - 1, "UTF8").intern();
+ return new String(b, 0, length, "UTF8").intern();
}
else
{
// use platform encoding
- return new String(b, 0, length - 1).intern();
+ return new String(b, 0, length).intern();
}
}
Translate