Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/net/sf/image4j/codec/ico/ICODecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public static java.util.List<ICOImage> readExt(java.io.InputStream is)
try {
for (i = 0; i < sCount; i++) {
// Make sure we're at the right file offset!
while (in.getCount() < entries[i].iFileOffset) {
in.skip(entries[i].iFileOffset - in.getCount(), false);
}
int fileOffset = in.getCount();
if (fileOffset != entries[i].iFileOffset) {
throw new IOException("Cannot read image #" + i
Expand Down
9 changes: 7 additions & 2 deletions src/net/sf/image4j/io/LittleEndianInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ public int getCount() {
return ((CountingInputStream) in).getCount();
}

public int skip(int count, boolean strict) throws IOException {
return IOUtils.skip(this, count, strict);
@Override
public long skip( long n ) throws IOException {
return skip( ( int )n, false );
}

public int skip( int count, boolean strict ) throws IOException {
return IOUtils.skip( this, count, strict );
}

/**
Expand Down
Binary file added test/net/sf/image4j/254.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions test/net/sf/image4j/ICODecoderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.sf.image4j;

import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import net.sf.image4j.codec.ico.ICODecoder;

public class ICODecoderTest {

@Test
public void checkSkipOnTooLongLayerDefinition() throws IOException {
// The image header is some bytes after the last layer definition, so the offset is higher than the current position
try(InputStream icon = ICODecoderTest.class.getResourceAsStream("254.ico")){
ICODecoder.read(icon);
}
}

}