Skip to content

Commit

Permalink
8241370: Crash in JPEGImageLoader after fix for JDK-8212034
Browse files Browse the repository at this point in the history
Reviewed-by: kcr
  • Loading branch information
arapte committed Apr 3, 2020
1 parent 159f651 commit 5906521
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 2 deletions.
3 changes: 1 addition & 2 deletions modules/javafx.graphics/src/main/native-iio/jpegloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,14 +1392,13 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_iio_jpeg_JPEGImageLoader_initDecompr
if (setjmp(jerr->setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error
while reading the header. */
disposeIIO(env, data);
if (!(*env)->ExceptionOccurred(env)) {
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message) ((struct jpeg_common_struct *) cinfo,
buffer);
ThrowByName(env, "java/io/IOException", buffer);
}

disposeIIO(env, data);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.com.sun.javafx.iio;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertTrue;

import test.util.Util;

public class LoadCorruptJPEGTest {
static CountDownLatch startupLatch;
static HBox root;
static volatile Scene scene;
static volatile Stage stage;
static final int SCENE_WIDTH = 200;
static final int SCENE_HEIGHT = 200;

@Test
public void testCorruptJPEGImage() {
Util.runAndWait(() -> {
URL resource = LoadCorruptJPEGTest.class.getResource("corrupt.jpg");
FileInputStream input = null;
try {
input = new FileInputStream(resource.getFile());
} catch (FileNotFoundException e) {
fail("File not found: corrupt.jpg");
}
Image image = new Image(input);
ImageView iv = new ImageView(image);
root.getChildren().add(iv);
});
}

public static class TestApp extends Application {
@Override
public void start(Stage primaryStage) {
stage = primaryStage;
root = new HBox();
scene = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT);
stage.setScene(scene);
stage.setOnShown(l -> {
Platform.runLater(() -> startupLatch.countDown());
});
stage.show();
}
}

@BeforeClass
public static void initFX() throws Exception {
startupLatch = new CountDownLatch(1);
new Thread(() -> Application.launch(TestApp.class, (String[])null)).start();
assertTrue("Timeout waiting for FX runtime to start",
startupLatch.await(15, TimeUnit.SECONDS));
}

@AfterClass
public static void exit() {
Util.runAndWait(() -> {
stage.hide();
});
Platform.exit();
}

@After
public void resetTest() {
Util.runAndWait(() -> {
root.getChildren().clear();
});
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5906521

Please sign in to comment.