Skip to content

Commit

Permalink
Handle case where initial read doesn't get enough data.
Browse files Browse the repository at this point in the history
This appears to get triggered on certain Java runtimes.
Under certain conditions, the image reader reads very small portions
at a time, which causes the initial implementation to fail.
This was observed in OpenJDK 9 and 11.
  • Loading branch information
coobird committed Feb 9, 2022
1 parent 644d501 commit 3a63909
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Thumbnailator - a thumbnail generation library
*
* Copyright (c) 2008-2021 Chris Kroells
* Copyright (c) 2008-2022 Chris Kroells
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -380,6 +380,14 @@ public int read(byte[] b, int off, int len) throws IOException {
}
}

if (totalRead <= 6) {
// SOI (2 bytes) + marker+length (4 bytes) == 6 bytes
// If we didn't find a 2-byte (standalone) marker, then
// we'll need to wait around to get enough one for 4-byte.
debugln("Not enough data read. Attempt one additional read.");
break;
}

terminateIntercept();
debugln("Shouldn't be here. Terminating intercept.");
break;
Expand Down

0 comments on commit 3a63909

Please sign in to comment.