SFML community forums

Help => Graphics => Topic started by: BZep on April 09, 2015, 01:00:03 am

Title: Trying to load glitched JPG file causes access violation
Post by: BZep on April 09, 2015, 01:00:03 am
Yo,

So basically I was messing around with some JPEG-glitching. I changed some bytes between the end of the JPEG header and EOF and tried to display the new image, but encountered access violations. Sometimes the image loading would work, sometimes it would not, and I can't figure out when and why. :(

This is a glitched image that makes the application throw an exception:
(http://autistklassen.dk/newpic.jpg)

Here is a minimal example:

#include <SFML\Graphics.hpp>

int main() {

        sf::RenderWindow window(sf::VideoMode(800, 600), "G-Glitch", sf::Style::Close);
        sf::Texture tex; tex.loadFromFile("newpic.jpg");

        sf::Sprite spr(tex);

        sf::Event event;
        while(window.isOpen()) {
                while(window.pollEvent(event)) {
                        switch(event.type) {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        }
                }

                window.clear();
                window.draw(spr);
                window.display();
        }

        return 0;
}
 

The weird thing is that the image displays just fine in my browser and native image viewer.. Can someone please explain this phenomenon?

I'm not linking debug code with release libraries or vice versa. I've been using SFML for a couple of years now. ;^)

~BZep

EDIT!:
Here is the original picture to actually prove that the other particular picture is causing misfits:
(http://i.imgur.com/1xLHkLi.jpg)
Title: AW: Trying to load glitched JPG file causes access violation
Post by: eXpl0it3r on April 09, 2015, 07:03:58 am
Use debug libs and run it through the debugger. Tools exist for a reason. ;)
Title: Re: Trying to load glitched JPG file causes access violation
Post by: Laurent on April 09, 2015, 08:01:12 am
The fact that other tools are able to display your possibly corrupted image, doesn't mean that it is valid. We're using a small library, stb_image (https://github.com/nothings/stb/blob/master/stb_image.h), to load images in SFML, and it may be able to handle some cases of incorrect data, but certainly not all.

Unless you can prove that your modified image is still a valid JPEG file, or that your modification is likely to happen to real-life JPEGs, nobody will take the time to find a "fix" for you.
Title: Re: Trying to load glitched JPG file causes access violation
Post by: BZep on April 09, 2015, 10:48:34 am
The fact that other tools are able to display your possibly corrupted image, doesn't mean that it is valid. We're using a small library, stb_image (https://github.com/nothings/stb/blob/master/stb_image.h), to load images in SFML, and it may be able to handle some cases of incorrect data, but certainly not all.

Unlless you can prove that your modified image is still a valid JPEG file, or that your modification is likely to happen to real-life JPEGs, nobody will take the time to find a "fix" for you.

That's basically what I wanted to know. ^_^

Seems I'll have to get in depth with the JPG format then.
Title: AW: Trying to load glitched JPG file causes access violation
Post by: eXpl0it3r on April 09, 2015, 11:02:59 am
What are you trying to achieve?