Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to load glitched JPG file causes access violation  (Read 2091 times)

0 Members and 1 Guest are viewing this topic.

BZep

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Trying to load glitched JPG file causes access violation
« 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:


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:

« Last Edit: April 09, 2015, 01:12:05 am by BZep »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: Trying to load glitched JPG file causes access violation
« Reply #1 on: April 09, 2015, 07:03:58 am »
Use debug libs and run it through the debugger. Tools exist for a reason. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Trying to load glitched JPG file causes access violation
« Reply #2 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, 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.
« Last Edit: April 09, 2015, 11:17:48 am by Laurent »
Laurent Gomila - SFML developer

BZep

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: Trying to load glitched JPG file causes access violation
« Reply #3 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, 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: Trying to load glitched JPG file causes access violation
« Reply #4 on: April 09, 2015, 11:02:59 am »
What are you trying to achieve?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/