program crashes on wxImage::LoadFile Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

program crashes on wxImage::LoadFile

Post by cutecode »

How to check if image file is wrong before loading it with wxImage::LoadFile?
My program crashes if file is wrong
7Y1Ns-B7Uv2-27hPH-J2ibo.gif
7Y1Ns-B7Uv2-27hPH-J2ibo.gif (32.27 KiB) Viewed 3298 times

Code: Select all

      wxImage im;
        if(im.LoadFile(sz))
All prgograms are showing this file without any error
Why wxImage::LoadFile crashes?
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: program crashes on wxImage::LoadFile

Post by PB »

cutecode wrote: Fri Mar 31, 2023 7:24 am Why wxImage::LoadFile crashes?
Probably due to to a bug in wxGIFDecoder::getcode(), where it tries to write many more bytes to the buffer than the buffer actually has (in your image 4294967295 vs 256).

Will you report this bug or should I do it?
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: program crashes on wxImage::LoadFile

Post by cutecode »

I don't know how to do it.
I would be grateful if you do it.

Thank you.
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: program crashes on wxImage::LoadFile

Post by PB »

User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: program crashes on wxImage::LoadFile

Post by cutecode »

WOW

Thank you.
Nice full description.
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: program crashes on wxImage::LoadFile

Post by PB »

I have also provided a blind fix, but it needs to be applied to wxWidgets code, can't be used from the user code.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: program crashes on wxImage::LoadFile

Post by ONEEYEMAN »

Alex,
Since the fix is blind - can you apply it to your local copy and see if it fixes the crash for you?

Thank you.
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: program crashes on wxImage::LoadFile

Post by cutecode »

Thank you this patch did help
I don't have any warning maybe because I put this line before LoadFile()
im.SetLoadFlags(im.GetLoadFlags() & ~wxImage::Load_Verbose);

Code: Select all

         wxImage im;
        im.SetLoadFlags(im.GetLoadFlags() & ~wxImage::Load_Verbose);
        if(im.LoadFile(sz))
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: program crashes on wxImage::LoadFile

Post by ONEEYEMAN »

Hi,
Is the image displayed or it just doesn't crash?

Thank you.
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: program crashes on wxImage::LoadFile

Post by cutecode »

It's partially displayed
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
Post Reply