LibGfx: Treat PNG files with invalid frame data as transparent

If we have a valid PNG header with geometry info etc, we should still
display it as *something*, even if the image data itself is missing or
corrupted.

This matches the behavior of other browsers, and is something that
Cloudflare Turnstile checks for.

To achieve this, we split the PNG decoder's initialization into two
steps: "everything except reading frame data" and "reading frame data".
If the latter step fails, we yield a transparent bitmap with the
geometry from the PNG's IHDR chunk.
This commit is contained in:
Andreas Kling 2024-12-18 08:54:05 +01:00 committed by Andreas Kling
commit 9164c9784d
Notes: github-actions[bot] 2024-12-19 15:50:30 +00:00
3 changed files with 73 additions and 29 deletions

View file

@ -0,0 +1,16 @@
<script src="../include.js"></script>
<script>
asyncTest(done => {
const image = document.createElement("img");
image.onload = () => {
println(`loaded, width=${image.width}, height=${image.height}`);
done();
};
image.onerror = () => {
println("error :^(");
done();
};
image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAABhCAIAAAABe4UxAAAABElEQVQAAAABnSTXkQAAAABJRU5ErkJggg==";
});
</script>