gildas-lormeau / Polyglot-HTML-ZIP-PNG

Learn how to create HTML/ZIP/PNG polyglot files in JavaScript
https://gildas-lormeau.github.io/Polyglot-HTML-ZIP-PNG/
MIT License
19 stars 1 forks source link

CRC Error #1

Closed nanderer closed 1 week ago

nanderer commented 1 week ago

Hi,

i tested optipng on your demo at

https://raw.githubusercontent.com/gildas-lormeau/Polyglot-HTML-ZIP-PNG/main/demo.png.zip.html

the most fascinating thing that i found is that optipng didn't destroy the html part, its really good masked using this tEXtPNG thingy, quite fascinating` what you can do, but it showed a crc error:

$ optipng demo.png.zip.html 
** Processing: demo.png.zip.html
Warning: tEXt: CRC error
Warning: tEXt: CRC error
271x406 pixels, 8 bits/pixel, 255 colors in palette
Recoverable errors found in input. Rerun OptiPNG with -fix enabled.
Error: Previous error(s) not fixed

** Status report
1 file(s) have been processed.
1 error(s) have been encountered.
$ optipng demo.png.zip.html  --fix
** Processing: demo.png.zip.html
Warning: tEXt: CRC error
Warning: tEXt: CRC error
271x406 pixels, 8 bits/pixel, 255 colors in palette
Recoverable errors found in input. Fixing...
Input IDAT size = 10733 bytes
Input file size = 84292 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0     IDAT size = 11609

Selecting parameters:
  zc = 9  zm = 8  zs = 0  f = 0     IDAT size = 11609

Output IDAT size = 11609 bytes (876 bytes increase)
Output file size = 85168 bytes (876 bytes = 1.04% increase)

** Status report
1 file(s) have been processed.
1 error(s) have been encountered.
1 erroneous file(s) have been fixed.
$ 
gildas-lormeau commented 1 week ago

Thank you very much for the info! I'll check it out as soon as I can. The demo.png.zip.html fle is also suferring from the same issue. The strange thing is that https://www.nayuki.io/page/png-file-chunk-inspector tells me that CRCs are OK (it displays a warning when they are not)...

EDIT: I have some doubts that https://www.nayuki.io/page/png-file-chunk-inspector really validates CRCs

gildas-lormeau commented 1 week ago

I'd be willing to bet it's related to a text encoding issue....

gildas-lormeau commented 1 week ago

In fact, the mistake was simpler than I guessed. Now the PNG file is valid.

nayuki commented 1 week ago

EDIT: I have some doubts that https://www.nayuki.io/page/png-file-chunk-inspector really validates CRCs

It does validate CRCs strictly. It would be easy to test it yourself by opening a PNG file in a hex editor and altering a few bytes.

gildas-lormeau commented 1 week ago

EDIT: I have some doubts that https://www.nayuki.io/page/png-file-chunk-inspector really validates CRCs

It does validate CRCs strictly. It would be easy to test it yourself by opening a PNG file in a hex editor and altering a few bytes.

This is what I did with the corrupted and the fixed file yesterday but it was 2:00 AM, maybe I was too tired...

gildas-lormeau commented 1 week ago

For the record, I confirm that no warning messages are displayed when the CRC is wrong on https://www.nayuki.io/page/png-file-chunk-inspector unfortunately. See the screenshots below (done with the old and new demo files). I've sent an email to the author about this issue.

CRC OK: image

Bad CRC: image

nayuki commented 1 week ago

I see that the humongous amount of tEXt is causing a visual overflow. Did you try scrolling the web page horizontally to the right?

gildas-lormeau commented 1 week ago

@nayuki Sorry for the inconvenience, I can confirm that all I had to do was scroll the page to the right. See the screenshot below. Thank you very much for your help :)

image

nayuki commented 1 week ago

@gildas-lormeau Thanks for your patience and understanding. With the help of your tricky test case, I went ahead and fixed the issue with "PNG file chunk inspector" for the long term. Now there are forced line breaks in any potentially long user-supplied text, which makes it far less likely for the rightmost column (error column) of the table to disappear.

gildas-lormeau commented 1 week ago

@nayuki I confirm your fix works perfectly, thank you very much!