transform-swf icon indicating copy to clipboard operation
transform-swf copied to clipboard

Non-terminating Loop

Open msandin opened this issue 14 years ago • 4 comments

Using SWF Transform 3.02 I have at least two SWF files (crawled from the web) which causes a hang in the library whilst parsing.

    at com.flagstone.transform.coder.SWFDecoder.fill(SWFDecoder.java:150)
    at com.flagstone.transform.coder.SWFDecoder.readBytes(SWFDecoder.java:461)
    at com.flagstone.transform.action.ActionObject.<init>(ActionObject.java:77)
    at com.flagstone.transform.action.ActionDecoder.getObject(ActionDecoder.java:116)
    at com.flagstone.transform.action.With.<init>(With.java:95)
    at com.flagstone.transform.action.ActionDecoder.getObject(ActionDecoder.java:107)
    at com.flagstone.transform.EventHandler.<init>(EventHandler.java:306)
    at com.flagstone.transform.Place2.<init>(Place2.java:328)
    at com.flagstone.transform.MovieDecoder.getObject(MovieDecoder.java:171)
    at com.flagstone.transform.Movie.decodeFromStream(Movie.java:310)
    at com.apptus.documents.parsing.swf.SWFContentGenerator.movie(SWFContentGenerator.java:178)
    at com.apptus.documents.parsing.swf.SWFContentGenerator.parse(SWFContentGenerator.java:63)

    ...(application stack culled) 

Looking at the code using GrepCode I'm guessing that the SWF isn't well-formed and that the inner SWFDecoder.fill(...) does not advance because the stream is empty and this condition is not detected by the outer SWFDecoder.readBytes(...), causing it to loop forever. This is however conjecture, I do not understand the code well enough.

Thanks for looking at this issue, Martin

msandin avatar Oct 10 '11 13:10 msandin

Martin, sorry for the delay in looking at this - I've been busy with my new life as a python/django dev. Transform SWF aims to decode most Flash files but there are quite a few bugs and even more badly formed files out there. The code is able to handle a few of the more common cases and tries to be robust when there is enough information to recover but in many cases the code simple cannot recover from arbitrary errors in a file.

StuartMacKay avatar Feb 07 '12 09:02 StuartMacKay

I don't really mind terribly that it does not handle every case so throwing an exception is fine but it's a bit of a problem that it in fact hangs while decoding. If I do submit a patch would you consider accepting it?

msandin avatar Feb 07 '12 11:02 msandin

Patches are good. If you have a swf file that fails could you send it to me so I can take a look ?

Cheers,

Stuart

StuartMacKay avatar Feb 07 '12 12:02 StuartMacKay

I'll go look for that. Meanwhile I believe the problem is the following loop SWFDecoder#readBytes:

        while (read < wanted) {
            available = size - index;
            remaining = wanted - read;
            if (available > remaining) {
                available = remaining;
            }
            System.arraycopy(buffer, index, bytes, dest, available);
            read += available;
            index += available;
            dest += available;

            if (index == size) {
                fill();
            }
        }

The termination clause (read < wanted) does not take into account that fill() might reach the end of the stream without actually reading enough bytes and will in such a case loop forever waiting for fill() which will continuously return without actually reading anything.

msandin avatar Feb 09 '12 12:02 msandin