PureBasic Forum
https://www.purebasic.fr/english/

[Done] IMA on certain header information in TGA image files.
https://www.purebasic.fr/english/viewtopic.php?f=4&t=72364
Page 1 of 1

Author:  Xanos [ Wed Feb 27, 2019 2:19 pm ]
Post subject:  [Done] IMA on certain header information in TGA image files.

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.

Author:  Kiffi [ Wed Feb 27, 2019 2:36 pm ]
Post subject:  Re: Invalid Memory Access with LoadImage()

No bug.

Always check the return value of ReceiveHTTPFile()!

Author:  Xanos [ Wed Feb 27, 2019 2:39 pm ]
Post subject:  Re: Invalid Memory Access with LoadImage()

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?

Author:  Paul [ Wed Feb 27, 2019 3:03 pm ]
Post subject:  Re: Invalid Memory Access with LoadImage()

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.

Author:  RASHAD [ Wed Feb 27, 2019 3:28 pm ]
Post subject:  Re: Invalid Memory Access with LoadImage()

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

Author:  Xanos [ Wed Feb 27, 2019 3:41 pm ]
Post subject:  Re: Invalid Memory Access with LoadImage()

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.

Author:  djes [ Wed Feb 27, 2019 6:24 pm ]
Post subject:  Re: Invalid Memory Access with LoadImage()

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.

Author:  Fred [ Wed Apr 10, 2019 8:02 pm ]
Post subject:  Re: IMA on certain header information in TGA image files.

Fixed.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/