Recent

Author Topic: fpExif - range check error  (Read 1062 times)

Mirkasp

  • Newbie
  • Posts: 3
fpExif - range check error
« on: July 28, 2022, 09:09:56 pm »
Hi wp!
The fpExif package is super, but in my application, in same jpg files I have run-time error: "Range check error" in file fpeutils.pas at line 1370.
Maybe the following code would be more appropriate:
Code: Pascal  [Select][+][-]
  1. function PosInBytes( const AText: AnsiString; ABuffer: TBytes ): Integer;
  2.   var n: Integer;
  3. begin
  4.   n := Length( AText );
  5.   if (n > 0) and Assigned( ABuffer ) then begin
  6.     for Result := Low( ABuffer ) to High( ABuffer )-n+1 do
  7.       if {%H-}CompareMem( @ABuffer[ Result ], Pointer( AText), n ) then
  8.         exit;
  9.   end;
  10.   Result := -1;
  11. end;
  12.  
A sample jpg file is attached.

I have also a lot of unsupported exif tags in second attachment. Please check them and add them to fpeexifdata.pas

Sorry for my english :)
Best regards
MirKasp

Awkward

  • Full Member
  • ***
  • Posts: 135
Re: fpExif - range check error
« Reply #1 on: July 28, 2022, 09:55:02 pm »
looks like you comparing pointers as is but not content on their address

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Re: fpExif - range check error
« Reply #2 on: July 28, 2022, 10:45:58 pm »
if n=length(abuffer)=high(abuffer)+1


what is high(abuffer)-n+1  supposed to do? It always evaluates to zero.

High and low on dynamic arrays (as opposed to open arrays) are a bit shady anyway, and I don't know if that works. Iteration on dynamic arrays are 0..length(arr)-1.

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: fpExif - range check error
« Reply #3 on: July 28, 2022, 11:16:38 pm »
Applied.

what is high(abuffer)-n+1  supposed to do? It always evaluates to zero.
No. n is the length of the string, not the length of buffer. The code makes sure that the last comparison run starts at such an index that the comparison with the text bytes just stays inside the buffer.

looks like you comparing pointers as is but not content on their address
That's the way CompareMem is called, it has the pointers to the start of the memory blocks to be compared as parameters (https://www.freepascal.org/docs-html/rtl/sysutils/comparemem.html).

I have also a lot of unsupported exif tags in second attachment. Please check them and add them to fpeexifdata.pas
Please provide images that show that these tags really exist (at least some of them). What your patch is doing is moving tags which should be in the Exif directory into the primary directory, for example.

Mirkasp

  • Newbie
  • Posts: 3
Re: fpExif - range check error
« Reply #4 on: July 29, 2022, 09:11:43 pm »
Thank you, it works fine now.
Quote
Please provide images that show that these tags really exist (at least some of them). What your patch is doing is moving tags which should be in the Exif directory into the primary directory, for example.
I wrote an application lxImgScanner http://mikron.epizy.com/strona-glowna/lximgscanner-2/ that uses fpExif and looks for unnamed tags in jpg files. Please check it.
An example with an unnamed tag attached.

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: fpExif - range check error
« Reply #5 on: July 29, 2022, 10:47:57 pm »
How are these unnamed tags reported by ExifTool?

Mirkasp

  • Newbie
  • Posts: 3
Re: fpExif - range check error
« Reply #6 on: July 29, 2022, 10:58:09 pm »
How to do it? I don't know ExifTool very well.

 

TinyPortal © 2005-2018