Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Feb 28, 2024
2 parents eef0ca1 + 9b655bf commit ff2dbf7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ private BmpImageContents readImageContents(final InputStream is, final FormatCom
debugNumber("expectedDataOffset", expectedDataOffset, 4);
}
final int extraBytes = bhi.bitmapDataOffset - expectedDataOffset;
if (extraBytes < 0) {
if (extraBytes < 0 || extraBytes > bhi.fileSize) {
throw new ImagingException("BMP has invalid image data offset: " + bhi.bitmapDataOffset + " (expected: " + expectedDataOffset + ", paletteLength: "
+ paletteLength + ", headerSize: " + headerSize + ")");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.imaging.formats.ico;

import static org.junit.jupiter.api.Assertions.assertThrows;

import org.apache.commons.imaging.ImagingException;
import org.apache.commons.imaging.test.TestResources;
import org.junit.jupiter.api.Test;

import java.io.File;

public class IcoImageParserTest {

/**
* For <a href="https://issues.apache.org/jira/browse/IMAGING-373">IMAGING-373</a>.
* <p>There is a problem with loading bitmap stored in given ICO file, so the exception is originally thrown by BmpImageParser.</p>
*/
@Test
public void testImageWithInvalidBmpHeaders() {
final File ico = TestResources.resourceToFile("/IMAGING-373/OutOfMemory_epine.ico");
final IcoImageParser parser = new IcoImageParser();
assertThrows(ImagingException.class, () -> parser.getAllBufferedImages(ico));
}
}
Binary file not shown.

0 comments on commit ff2dbf7

Please sign in to comment.