Skip to content

stb_image: fix CRC reading at the end of IEND chunk in png file#835

Merged
nothings merged 1 commit intonothings:masterfrom
Try:master
Feb 2, 2020
Merged

stb_image: fix CRC reading at the end of IEND chunk in png file#835
nothings merged 1 commit intonothings:masterfrom
Try:master

Conversation

@Try
Copy link
Copy Markdown
Contributor

@Try Try commented Nov 18, 2019

The problem

stb consistently under reads last 4 bytes of *png file.

Why this happends

in function stbi__parse_png_file we have a code:

static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
{
...
   for (;;) {
      stbi__pngchunk c = stbi__get_chunk_header(s);
      switch(c.type) {
        ...
        case STBI__PNG_TYPE('I','E','N','D'): {
            ...
            return 1; // <--- CRC-read, will be skipped because of this 'return'
        }
      }
      ...
      stbi__get32be(s); // for normal chunk stb reading CRC here
   }
}

Why this is a problem

In my video-game I have a screen-shoot inside save-file binary:

[ header ][ png-priview ][ data ]

And to make it work I need a byte-exact png-reader/writer.

@nothings
Copy link
Copy Markdown
Owner

Makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants