This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git

commit 99b593e59f2cacbcee8d9c86873d342603faefc2
Author: Stefan Oltmann <git...@stefan-oltmann.de>
AuthorDate: Sun Feb 4 13:29:57 2024 +0100

    [IMAGING-319]: Fix EXIF metadata is discarded when updating offsets (wrong 
calculation)
---
 src/changes/changes.xml                                          | 5 ++++-
 .../imaging/formats/tiff/write/TiffImageWriterLossless.java      | 9 ++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 014a92a5..074e298f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,10 +48,13 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
     <release version="1.0.0-alpha5" date="YYYY-MM-DD" description="The 
1.0.0-alpha5 release requires Java 8.">
       <!-- FIX -->
+      <action issue="IMAGING-319" dev="kinow" type="fix" due-to="Stefan 
Oltmann, Gary Lucas">
+        Fix EXIF metadata is discarded when updating offsets (wrong 
calculation).
+      </action>
       <!-- UPDATE -->
       <action dev="ggregory" type="update" due-to="Dependabot">Bump 
org.apache.commons:commons-parent from 67 to 69 #382.</action>
       <action dev="ggregory" type="update" due-to="Dependabot">Bump 
commons-io:commons-io from 2.16.0 to 2.16.1 #385.</action>
-      <action issue="IMAGING-351" dev="kinow" type="update" due-to="Stefan 
Oltmann, Gary Lucas">
+      <action issue="IMAGING-351" dev="kinow" type="update" due-to="Stefan 
Oltmann, Gary Lucas, Charles Hope">
         Fix ExifRewriterRoundtripTest that was disabled.
       </action>
     </release>
diff --git 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
index 2648dda2..f73ad783 100644
--- 
a/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
+++ 
b/src/main/java/org/apache/commons/imaging/formats/tiff/write/TiffImageWriterLossless.java
@@ -206,16 +206,19 @@ public class TiffImageWriterLossless extends 
AbstractTiffImageWriter {
                 overflowIndex += outputItemLength;
             } else {
                 long offset = bestFit.offset;
+                int length = bestFit.length;
                 if ((offset & 1L) != 0) {
+                    // offsets have to be at a multiple of 2
                     offset += 1;
+                    length -= 1;
                 }
                 outputItem.setOffset(offset);
                 unusedElements.remove(bestFit);
 
-                if (bestFit.length > outputItemLength) {
+                if (length > outputItemLength) {
                     // not a perfect fit.
-                    final long excessOffset = bestFit.offset + 
outputItemLength;
-                    final int excessLength = bestFit.length - outputItemLength;
+                    final long excessOffset = offset + outputItemLength;
+                    final int excessLength = length - outputItemLength;
                     unusedElements.add(new 
AbstractTiffElement.Stub(excessOffset, excessLength));
                     // make sure the new element is in the correct order.
                     unusedElements.sort(ELEMENT_SIZE_COMPARATOR);

Reply via email to