From 62f3c0a5cb4bead2e39cfd66d8bbda0584fc0f4a Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 13 Nov 2023 17:35:49 +0000 Subject: [PATCH] fpexif: Avoid crash when xmp data have trainling zero bytes. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9024 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpexif/fpemetadata.pas | 3 ++- components/fpexif/fpexmpdata.pas | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/fpexif/fpemetadata.pas b/components/fpexif/fpemetadata.pas index 478a3f799..162fa557a 100644 --- a/components/fpexif/fpemetadata.pas +++ b/components/fpexif/fpemetadata.pas @@ -661,7 +661,8 @@ begin M_EOI, M_SOS: break; end; - AStream.Position := p + size; + p := p + Size; + AStream.Position := p; end; // Force writing of JFIF if it coexists with EXIF. diff --git a/components/fpexif/fpexmpdata.pas b/components/fpexif/fpexmpdata.pas index 09c280741..86045b2bf 100644 --- a/components/fpexif/fpexmpdata.pas +++ b/components/fpexif/fpexmpdata.pas @@ -280,6 +280,14 @@ begin FData[1] := '<'; end; + // The xml parser does not like zero bytes at the end --> remove them + i := Length(FData); + while (FData[i] = #0) and (i > 0) do + begin + dec(i); + SetLength(FData, i); + end; + AStream.Position := p; CreateTags; end;