-
Notifications
You must be signed in to change notification settings - Fork 203
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
fix stbi__parse_png_file() reading too much bytes #526
fix stbi__parse_png_file() reading too much bytes #526
Conversation
just "rewind" the bytes that have been read past the IEND chunk. should fix libsdl-org#360 and libsdl-org#524
@flowCRANE could you check if that fixes your issue ? I added a couple of bytes at the end of a file and checked using ftell() that is is indeed rewinding the additional bytes ;) I guess I should submit the patch to https://github.com/nothings/stb if it works for you |
If it works for you, it will work for me. You can test it on my sample file — test.files.zip (inside is If you are able to open Stream := SDL_IOFromFile('sdl.dat', 'rb');
Image1 := IMG_LoadTexture_IO(Renderer, Stream, False);
Image2 := IMG_LoadTexture_IO(Renderer, Stream, False); then it means that your fix is correct and solves the problem. And thanks so much for looking into this topic and finding the cause of the problems! |
Some Pascal :) @flowCRANE So you are not able to test the patch ? |
With the following code, img2 is null without the patch and is not null with the patch. {
SDL_IOStream *src = SDL_IOFromFile("/home/nanard/code/git/SDL_image/sdl.dat", "rb");
SDL_Texture *img1 = IMG_LoadTexture_IO(renderer, src, false);
SDL_Texture *img2 = IMG_LoadTexture_IO(renderer, src, true);
printf("src=%p img1=%p img2=%p\n", src, img1, img2);
} |
Merged, thanks! |
@miniupnp: yeah, I'm in Free Pascal's camp and have no thought of betraying the colors. ;) The main idea is that the data stream can be constructed in such a way that multiple PNG images can be written one after the other and that they can be loaded one after the other, like in the example above. This will mean that when the image is read, the pointer is in the correct place. I haven't done extensive testing, so I don't know if the same problem exists for other formats. But I'll look into it and let you know if I find anything. Thanks again for the fix! |
Add to SDL2 branch too. And also to SDL3 main repo? |
Yep, done |
just "rewind" the bytes that have been read past the IEND chunk.
should fix #360 and #524