1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.imaging.formats.png;
19
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21
22 import java.io.File;
23
24 import org.apache.commons.imaging.ImagingException;
25 import org.apache.commons.imaging.examples.ImageReadExample.ManagedImageBufferedImageFactory;
26 import org.apache.commons.imaging.test.TestResources;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32 public class PngWithInvalidPngChunkSizeTest {
33
34
35
36
37 @Test
38 public void testPngWithInvalidNegativePngChunkSize() {
39 final File imageFile = TestResources.resourceToFile("/IMAGING-210/testfile.png");
40 final PngImagingParameters params = new PngImagingParameters();
41 params.setBufferedImageFactory(new ManagedImageBufferedImageFactory());
42 final PngImageParser jpegImageParser = new PngImageParser();
43 assertThrows(ImagingException.class, () -> jpegImageParser.getBufferedImage(imageFile, params));
44 }
45
46
47
48
49 @Test
50 public void testPngWithInvalidPngChunkSize() {
51 final File imageFile = TestResources.resourceToFile("/IMAGING-211/testfile_2.png");
52 final PngImagingParameters params = new PngImagingParameters();
53 params.setBufferedImageFactory(new ManagedImageBufferedImageFactory());
54 final PngImageParser jpegImageParser = new PngImageParser();
55 assertThrows(ImagingException.class, () -> jpegImageParser.getBufferedImage(imageFile, params));
56 }
57 }