Skip to content
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

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

Merged
merged 1 commit into from
Feb 2, 2020

Conversation

Try
Copy link
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
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