-
Notifications
You must be signed in to change notification settings - Fork 259
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
Infinite loop if I decode a abnormal arraybuffer #13
Comments
Hi, this function is only used for Encoding PNG, not for decoding. What kind of "abnormal" ArrayBuffer did you put into it? |
oh, I copy wrong line. Line 480 in c62ddc8
Abnormal arraybuffer obtained by FileReader API. |
How long is your ArrayBuffer? What makes it "abnormal" ? Can you send us your PNG file to support@photopea.com ? |
The image, that you sent us, is a JPG image. This library can work only with PNG images. You should use some different library for parsing JPG images. |
I pay no attention to its size. Looks very small. And log “unknow chunk type”. |
I tried to open your APNG with this version of UPNG.js and it works well. Can you try to update your UPNG.js file? Are you sure you are sending an arraybuffer into decode(), not your FileReader or anything else? |
It works fine if using ArrayBuffer from 'correct' but not FileReader. |
what do you mean by "correct"? whenever UPNG gets a valid PNG file, it should decode it in finite time. |
demo1 - demo2 - |
In your picture, I see a message, that your PNG file was not found. This is not related to UPNG.js The message from UPNG.js basically says, that you are not giving it a PNG file, but some other file (like PDF or EXE or something). |
I mean that unexpected arraybuffer should not cause UPNG.js blocking browser, because sometimes we don't kown whether the arraybuffer decoded by UPNG.js is excepted or not. (Inexistence png is just for demo) |
Ok, I added some basic PNG check. If the ArrayBuffer on the input is not a PNG file, it should throw an exception. |
UPNG.js/UPNG.js
Lines 350 to 387 in c62ddc8
Above code would run infinite loop if I decode a abnormal arraybuffer, which block main JS thread, and will crash page.
Consider using setTimeout or web worker, and I think it's better to apply decode timeout.
The text was updated successfully, but these errors were encountered: