-
Notifications
You must be signed in to change notification settings - Fork 177
Open
Description
Our SWT-based application tries to read files first as image before it tries to read it as a text. This works quite good in detecting images. However, a customer found now a text file which causes an OOME because of missing sanity checks in the image loader code.
Describe the bug
new ImageData(stream)
interpretes even extremely large image width/height as valid and tries to load them; potentially resulting in an OOME.
To Reproduce
Use this snippet
import java.io.*;
import java.nio.file.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
final class ImageDisplayer {
public static void main(String[] args) throws IOException {
if (args.length != 1) {
return;
}
final ImageData imageData;
try (InputStream stream = Files.newInputStream(Paths.get(args[0]))) {
imageData = new ImageData(stream);
}
final Display display = new Display();
final Image image = new Image(display, imageData);
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Label label = new Label(shell, SWT.NONE);
label.setImage(image);
shell.setSize(400, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
image.dispose();
display.dispose();
}
}
Run with -Xmx256m
and specify a file with this content
BM2D_003.fxf &
21222-2259+22_EF1.55_KTT1_INR_LNR_2esbnf_tjg ^
Expected behavior
I expect to get an SWT-error for invalid image, but I'm getting an OOME.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
sebastien-ssdc
Metadata
Metadata
Assignees
Labels
No labels