kinow commented on PR #359:
URL: https://github.com/apache/commons-imaging/pull/359#issuecomment-2053761797
Thanks @StefanOltmann . I searched my hard drive for JPEG images to check if
I could reproduce the issue with any, but only the IMAGING-319 had this issue
(maybe it happened in another field, but I only tested for the Offset Time like
the issue reported).
```java
package org.apache.commons.imaging;
import org.apache.commons.imaging.common.ImageMetadata;
import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter;
import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
import org.apache.commons.io.IOUtils;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Search for images that cause the bug in IMAGING-319.
*/
public class LibraryTest {
public static void main(String[] args) throws ImagingException,
IOException, InterruptedException {
File path = new File("/home/kinow/Desktop/haystack/");
String needle = "Offset Time\\s+:\\s+";
Pattern pattern = Pattern.compile(String.format("^%s$", needle),
Pattern.MULTILINE);
for (File source : Objects.requireNonNull(path.listFiles(s ->
s.getName().toLowerCase().endsWith(".jpg")))) {
File result = Files.createTempFile("test_", ".jpg").toFile();
try {
final ImageMetadata metadata = Imaging.getMetadata(source);
final JpegImageMetadata jpegMetadata = (JpegImageMetadata)
metadata;
if (jpegMetadata != null) {
final TiffImageMetadata exif = jpegMetadata.getExif();
if (exif != null) {
TiffOutputSet outputSet = exif.getOutputSet();
BufferedOutputStream bufferedOutputStream = new
BufferedOutputStream(Files.newOutputStream(result.toPath()));
new
ExifRewriter().updateExifMetadataLossless(source, bufferedOutputStream,
outputSet);
String[] cmd = {
"/bin/sh",
"-c",
String.format("exiftool %s | grep \"Offset
Time\"", result.getAbsolutePath())
};
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
String output =
IOUtils.toString(process.getInputStream(), Charset.defaultCharset());
// System.out.println(output);
Matcher m = pattern.matcher(output);
if (m.find()) {
System.out.printf("Bug detected in %s%n",
source.getAbsolutePath());
}
}
}
} catch (RuntimeException|ImagingException ignore) {
ignore.printStackTrace();
} // invalid metadata or bad format
}
}
}
```
I will debug the code again to either craft a test image by hand, or write a
test code + mock. Let's see if that works...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]