Skip to content


Browse files Browse the repository at this point in the history
8241370: Crash in JPEGImageLoader after fix for JDK-8212034
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/
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,
ThrowByName(env, "java/io/IOException", buffer);

disposeIIO(env, data);
return 0;

Expand Down
@@ -0,0 +1,110 @@
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* 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 if you need additional information or have any
* questions.

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.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;
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;

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);

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

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));

public static void exit() {
Util.runAndWait(() -> {

public void resetTest() {
Util.runAndWait(() -> {
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.