eligrey / Blob.js

An HTML5 Blob implementation
Other
1.15k stars 605 forks source link

Safari iOS Maximum call stack size exceeded #6

Closed paulpdaniels closed 11 years ago

paulpdaniels commented 11 years ago

When attempting to use Blob.js in Safari for iOS using the Blob constructor results in a "Maximum call stack size exceeded" exception.

Seen on iOS 6.1.3 and 5.1.1

paulpdaniels commented 11 years ago

Edit: Tracked down the issue to this line (105):

    bb.push(String.fromCharCode.apply(String, new Uint8Array(data)));

It appears that on Safari iOS this function calls recursively for some reason.

Also noticed that the alternative case

var
       str = ""
    , buf = new Uint8Array(data)
    , i = 0
    , buf_len = buf.length
    ;
    for (; i < buf_len; i++) {
        str += String.fromCharCode(buf[i]);
    }

Doesn't appear to be doing anything.

levskaya commented 11 years ago

I'm having exactly the same problem with desktop OS X 10.8.3, Safari 6.0.4.

eligrey commented 11 years ago

@paulpdaniels I will accept any pull requests tested to work in IE10/Chrome/Firefox/Safari 6 if you have a solution.

OrNot commented 11 years ago

I got the same problem in win7 /safari 5.1.7 when to save a canvas which size is bigger than some value.

The demo is fine.

kardave commented 11 years ago

We ran into this bug too, and found that this happens when the data is too large. Here is a fix for Blob.js: replace this line (around line 105) bb.push(String.fromCharCode.apply(String, new Uint8Array(data)));

with this: var str = "", array = new Uint8Array(data); for (var i = 0, len = array.length; i < len; i++) { str += String.fromCharCode(array[i]); } bb.push(str);

Have fun!

eligrey commented 11 years ago

Did this fix it for you?

kardave commented 11 years ago

I could only check this on Safari, Win7. There the fix working very well.

kciesielski commented 11 years ago

Works on OSX 10.8.4.

OrNot commented 11 years ago

yes,it did.

Eli Grey notifications@github.com wrote:

Did this fix it for you?

— Reply to this email directly or view it on GitHub.

OrNot commented 11 years ago

also works for ipad.

David Karacsony notifications@github.com wrote:

I could only check this on Safari, Win7. There the fix working very well.

— Reply to this email directly or view it on GitHub.

fxa commented 11 years ago

Just for completeness, it is not a recursion problem, but String.fromCharCode.apply() will push each element of the array to the arguments. The arguments are passed via the stack. So the maximum call stack size is exceeded with one single call

mathiasbynens commented 10 years ago

For future reference, the behavior observed here is basically https://bugs.webkit.org/show_bug.cgi?id=80797.