Closed Aqours closed 6 years ago
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. https://github.com/photopea/UPNG.js/blob/c62ddc812f23abe629134e8a1527f48fe5dab2c1/UPNG.js#L480
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”.
You can download here https://github.com/Aqours/APNG-Codec/blob/master/test/elephant.png
Look like iOS cannot download apng.
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. ArrayBuffer from FileReader maybe not suitable for UPNG.decode method, but it should not decode infinite loop, because sometimes we don't know whether the ArrayBuffer is suitable for UPNG.decode method or not.
what do you mean by "correct"? whenever UPNG gets a valid PNG file, it should decode it in finite time.
demo1 - http://git.hub.moe/laboratory/decode-apng-normal.html (open this link with modern browser)
this demo works fine.
demo2 - http://git.hub.moe/laboratory/decode-apng-abnormal.html
this demo does not work.
you will see some message on browser's console.
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) Throw an error or other ways might be better solution.
Ok, I added some basic PNG check. If the ArrayBuffer on the input is not a PNG file, it should throw an exception.
https://github.com/photopea/UPNG.js/blob/c62ddc812f23abe629134e8a1527f48fe5dab2c1/UPNG.js#L350-L387
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.