It is currently Mon Aug 19, 2019 9:57 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [Done] IMA on certain header information in TGA image files.
PostPosted: Wed Feb 27, 2019 2:19 pm 
Offline
User
User
User avatar

Joined: Sat Feb 28, 2015 1:20 pm
Posts: 45
Code:
EnableExplicit

UseTGAImageDecoder()

; for reproducing the IMA: get the specific file causing the issue if not in current directory
If FileSize("image_00.tga") <= 0
  InitNetwork()
  ReceiveHTTPFile("https://drive.google.com/uc?authuser=0&id=14evF7srXJCoIyTrZTHuuo353uBX1SzOQ&export=download", "image_00.tga")
  If FileSize("image_00.tga") <= 0
    Debug "could not retrieve file, please put file in working directory manually"
    End
  EndIf
EndIf


Define im
im = LoadImage(#PB_Any, "image_00.tga")
If im
  Debug "image loaded successfully"
  ; this is never reached on my system (PB 5.70 x64 windows)
  FreeImage(im)
EndIf
End

Tested with 5.70 LTS, Windows x64

I had this issues multiple times with different images files of PNG and TGA format...
The image files are acquired over the internet, so I do not have influence on the files directly. After re-saving the affected files with an image editor, they can be used in PB without problem.
But the program crashes on such images without any way for me to intercept.

Edit: the problem is that this particular file has non-zero color map specification bytes in the TGA header although it is not using any color map (image type 2: uncompressed true-color image)
PB should ignore the color map specification instead of crashing imo.

_________________
Programming on Windows 10 Pro / Windows 7 Enterprise / Linux Mint 19 / Manjaro Linux with PB 5, Python 3 and Go


Last edited by Xanos on Mon Mar 04, 2019 10:34 pm, edited 5 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Invalid Memory Access with LoadImage()
PostPosted: Wed Feb 27, 2019 2:36 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 02, 2004 1:20 pm
Posts: 1010
Location: Amphibios 9
No bug.

Always check the return value of ReceiveHTTPFile()!

_________________
Can't decide if i need a hug, an XXL coffee, 6 shots of vodka or 2 weeks of sleep.


Top
 Profile  
Reply with quote  
 Post subject: Re: Invalid Memory Access with LoadImage()
PostPosted: Wed Feb 27, 2019 2:39 pm 
Offline
User
User
User avatar

Joined: Sat Feb 28, 2015 1:20 pm
Posts: 45
HTTP stuff is only for you to get the file, I already have it in the CWD.
It is just for reproducing the bug, since it only occurs with certain image files.
Also, if file is not there, LoadImage will just return false, not IMA.

No bug = code executes normally for you? (if yes, then please specify PB version, OS, etc...)
and/or no bug = image is loaded?

_________________
Programming on Windows 10 Pro / Windows 7 Enterprise / Linux Mint 19 / Manjaro Linux with PB 5, Python 3 and Go


Top
 Profile  
Reply with quote  
 Post subject: Re: Invalid Memory Access with LoadImage()
PostPosted: Wed Feb 27, 2019 3:03 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 898
Location: Canada
If you load the TGA image into Photoshop and do nothing but re-save as TGA then LoadImage has no problems loading it, so there is definitely something about the downloaded TGA that LoadIMage does not like and crashes.

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Invalid Memory Access with LoadImage()
PostPosted: Wed Feb 27, 2019 3:28 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3379
The Image is TGA format no doubt
But it's Origin is Bottom-Left
PB TGA Codec support only TGA with Origin Top-Left and most of Image viewers
do the same

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Invalid Memory Access with LoadImage()
PostPosted: Wed Feb 27, 2019 3:41 pm 
Offline
User
User
User avatar

Joined: Sat Feb 28, 2015 1:20 pm
Posts: 45
In the meantime I also did look at the TGA header to identify possible errors in file.
The closest I can get to the original file by saving it with GIMP is a bottom-left without RLE.
The big differences I can spot right now are that the original TGA has a 1 byte image ID specified and describes the color map while it is not using any color map (true color).
When I replace the color map information from the header of the original file with zero bytes, PB can load the TGA without problems.

So to make the bug report more specific:
The color map data in the header is set although the current image type does not have a color map.
The color map bytes should simply be skipped by PB in this case.


Ah how much I would love using an open source lib instead in those moments ;-) Just fixing this and moving on... :)

@RASHAD:
Origin is not the issue, PB can load bottom-left and top-left without problem.

_________________
Programming on Windows 10 Pro / Windows 7 Enterprise / Linux Mint 19 / Manjaro Linux with PB 5, Python 3 and Go


Top
 Profile  
Reply with quote  
 Post subject: Re: Invalid Memory Access with LoadImage()
PostPosted: Wed Feb 27, 2019 6:24 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1792
Location: Pas-de-Calais, France
We had some issue in the past with malformed png images too. For a time we were using catchimage() and saveimage() in 32 bits. An update has corrected the issue for png, maybe you could use the same workaround for tga by now.


Top
 Profile  
Reply with quote  
 Post subject: Re: IMA on certain header information in TGA image files.
PostPosted: Wed Apr 10, 2019 8:02 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
Fixed.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye