mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
check jpeg file signature in genericImageParser
to fail early without further object allocation if source is not a jpeg.
This commit is contained in:
parent
fb75fea446
commit
851e8f6c8a
|
@ -129,6 +129,12 @@ public class genericImageParser extends AbstractParser implements Parser {
|
||||||
byte[] b;
|
byte[] b;
|
||||||
try {
|
try {
|
||||||
b = FileUtils.read(source);
|
b = FileUtils.read(source);
|
||||||
|
// check jpeg file signature (magic number FF D8 FF)
|
||||||
|
if ((b[0] != (byte) 0xFF) // cast to signed byte (-1)
|
||||||
|
|| (b[1] != (byte) 0xD8) //cast to signed byte (-40)
|
||||||
|
|| (b[2] != (byte) 0xFF)) {
|
||||||
|
throw new Parser.Failure("File has no jpeg signature", location);
|
||||||
|
}
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
ConcurrentLog.logException(e);
|
ConcurrentLog.logException(e);
|
||||||
throw new Parser.Failure(e.getMessage(), location);
|
throw new Parser.Failure(e.getMessage(), location);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user