1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.imaging.formats.jpeg;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23
24 import java.awt.image.BufferedImage;
25 import java.io.File;
26 import java.util.stream.Stream;
27
28 import org.apache.commons.imaging.ImageInfo;
29 import org.apache.commons.imaging.Imaging;
30 import org.apache.commons.imaging.ImagingException;
31 import org.apache.commons.imaging.bytesource.ByteSource;
32 import org.apache.commons.imaging.common.ImageMetadata;
33 import org.apache.commons.imaging.formats.tiff.TiffImagingParameters;
34 import org.apache.commons.imaging.internal.Debug;
35 import org.apache.commons.imaging.test.TestResources;
36 import org.junit.jupiter.api.Test;
37 import org.junit.jupiter.params.ParameterizedTest;
38 import org.junit.jupiter.params.provider.MethodSource;
39
40 public class JpegReadTest extends JpegBaseTest {
41
42 public static Stream<File> data() throws Exception {
43 return getJpegImages().stream();
44 }
45
46 @ParameterizedTest
47 @MethodSource("data")
48 public void test(final File imageFile) throws Exception {
49 final JpegImageParser jpegImageParser = new JpegImageParser();
50 final ImageMetadata metadata = jpegImageParser.getExifMetadata(ByteSource.file(imageFile), new TiffImagingParameters());
51
52
53 Debug.debug("metadata", metadata);
54
55 Debug.debug("ICC profile", Imaging.getIccProfile(imageFile));
56
57 final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
58 assertNotNull(imageInfo);
59
60 try {
61 final BufferedImage image = Imaging.getBufferedImage(imageFile);
62 assertNotNull(image);
63 } catch (final ImagingException imageReadException) {
64 assertEquals("Only sequential, baseline JPEGs are supported at the moment", imageReadException.getMessage());
65 }
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79 @Test
80 public void testUncaughtExceptionOssFuzz33458() {
81 final File file = TestResources.resourceToFile("/images/jpeg/oss-fuzz-33458/clusterfuzz-testcase-minimized-ImagingJpegFuzzer-4548690447564800");
82 final JpegImageParser parser = new JpegImageParser();
83 assertThrows(ImagingException.class, () -> parser.getBufferedImage(ByteSource.file(file), new JpegImagingParameters()));
84 }
85
86 }