Mercurial > hg > release > icedtea7-forest-2.6 > jdk
changeset 7646:b69f22ae0ef3 icedtea-2.6pre04
Merge jdk7u60-b15
author | andrew |
---|---|
date | Fri, 02 May 2014 20:39:34 +0100 |
parents | 06da90c6aaff (current diff) 04882f9a073e (diff) |
children | 8a9cfa3f0b7a |
files | .hgtags src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java src/share/classes/com/sun/naming/internal/ResourceManager.java src/share/classes/java/lang/invoke/MethodHandles.java src/share/native/com/sun/java/util/jar/pack/unpack.cpp src/share/native/sun/awt/image/jpeg/imageioJPEG.c src/share/native/sun/awt/image/jpeg/jpeg-6b/jdmarker.c src/share/native/sun/awt/image/jpeg/jpegdecoder.c src/share/native/sun/java2d/cmm/lcms/cmsxform.c src/solaris/classes/sun/awt/X11/XToolkit.java test/ProblemList.txt |
diffstat | 124 files changed, 2915 insertions(+), 1636 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Wed Apr 30 15:40:34 2014 +0100 +++ b/.hgtags Fri May 02 20:39:34 2014 +0100 @@ -380,6 +380,7 @@ db5a29c812ee25c34ce9cd97de6e0dae284a4e34 jdk7u60-b00 402d54c7d8ce95f3945cc3d698e528e4adec7b9b jdk7u45-b33 34e8f9f26ae612ebac36357eecbe70ea20e0233c jdk7u45-b34 +3dbb06a924cdf73d39b8543824ec88ae501ba5c6 jdk7u45-b35 3c9a6d9eafd31be44b0ade0354e60f5078b417a4 jdk7u51-b00 d76613074ff357d0664b97b4aaf99fbb65dcec47 jdk7u51-b01 fb057871f094ebe4906ad6856326768b01a62c45 jdk7u51-b02 @@ -396,6 +397,26 @@ d19a89fdfb9b959b8638441d9d396685d6c7ab7b jdk7u51-b13 ef58b2b9a9a1e1a42b0139b57816a160c4681371 jdk7u51-b30 5bca0d0969b13b1d9b8caba3cce8293a98d68318 jdk7u51-b31 +e9143dc3dc2a8f4b896e74f70d6c503d73c40533 jdk7u51-b33 +c1eaf405fb8d7beddd75c6f81671970f6baa70d8 jdk7u51-b34 +f5eee4f1d5b4a1e19febc9c26c863ae853ed6d2e jdk7u55-b00 +5010db5b9b5ab07a9409a5c557d3f43ab32dc428 jdk7u55-b01 +2ca3e1fa4455ad564228ad6e654498167af2f20d jdk7u55-b02 +c12b3c81366cb067ff4444952209d54bfa387353 jdk7u55-b03 +476d1bddaa32bf440953c3b1814ba38f16886c03 jdk7u55-b04 +7fa6d3ba2cc77cd1e6f24e33f0c39788cb2893b8 jdk7u55-b05 +795654fce29c38d4c8504f760d8d8a36248d38ed jdk7u55-b06 +4b2ed892b195e95f7541aaa3b129a2caa5faae1d jdk7u55-b07 +db1323224053a18ecc62bdc1d3902d93b33f0b70 jdk7u55-b08 +534eeff29ac9fcbbb99ef8908548dbb368d04baf jdk7u55-b09 +d39dd4135844ca5c707bc39ae1d7e020d49880ce jdk7u55-b09 +b231536550067c3b00c77d0e035afe8faaa15581 jdk7u55-b10 +2d80b7cd7aae76f0909a210414317dcf846ad651 jdk7u55-b11 +07be5d5508733ed37c11fcd21a13ae3c8288313b jdk7u55-b12 +92fd166252c2701092a510002f4cf9285a20473d jdk7u55-b13 +4a5651c84b1e6cf26dc9b19f00747e5004efba68 jdk7u55-b30 +ffd99c5975217a14609851602c5f5dc005234aba jdk7u55-b14 +88f1bf248cc520e0bf7ef17bc862f87aab958373 jdk7u55-b31 db5a29c812ee25c34ce9cd97de6e0dae284a4e34 jdk7u60-b00 def34c4a798678c424786a8f0d0508e90185958d jdk7u60-b01 ff67c89658525e8903fb870861ed3645befd6bc5 jdk7u60-b02 @@ -415,3 +436,4 @@ b06d4ed71ae0bc6e13f5a8437cb6388f17c66e84 jdk7u60-b13 6f22501ca73cc21960cfe45a2684a0c902f46133 icedtea-2.6pre02 068d2b78bd73fc2159a1c8a88dca3ca2841c4e16 icedtea-2.6pre03 +b7fbd9b4febf8961091fdf451d3da477602a8f1d jdk7u60-b14
--- a/src/macosx/classes/sun/font/CFontManager.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/font/CFontManager.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -27,6 +27,8 @@ import java.awt.*; import java.io.File; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; @@ -38,6 +40,7 @@ import sun.awt.FontConfiguration; import sun.awt.HeadlessToolkit; +import sun.misc.ThreadGroupUtils; import sun.lwawt.macosx.*; public class CFontManager extends SunFontManager { @@ -215,24 +218,22 @@ }); } }; - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction<Object>() { - public Object run() { + AccessController.doPrivileged( + new PrivilegedAction<Void>() { + @Override + public Void run() { /* The thread must be a member of a thread group * which will not get GCed before VM exit. * Make its parent the top-level thread group. */ - ThreadGroup tg = - Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; - tg = tgn, tgn = tg.getParent()); - fileCloser = new Thread(tg, fileCloserRunnable); + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + fileCloser = new Thread(rootTG, fileCloserRunnable); fileCloser.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(fileCloser); return null; } - }); + } + ); } } }
--- a/src/macosx/classes/sun/font/CStrike.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/font/CStrike.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 @@ -31,7 +31,7 @@ import sun.awt.SunHints; -public class CStrike extends FontStrike { +public final class CStrike extends FontStrike { // Creates the native strike private static native long createNativeStrikePtr(long nativeFontPtr, @@ -68,10 +68,10 @@ Rectangle2D.Float result, double x, double y); - private CFont nativeFont; + private final CFont nativeFont; private AffineTransform invDevTx; - private GlyphInfoCache glyphInfoCache; - private GlyphAdvanceCache glyphAdvanceCache; + private final GlyphInfoCache glyphInfoCache; + private final GlyphAdvanceCache glyphAdvanceCache; private long nativeStrikePtr; CStrike(final CFont font, final FontStrikeDesc inDesc) { @@ -84,11 +84,11 @@ // Normally the device transform should be the identity transform // for screen operations. The device transform only becomes // interesting when we are outputting between different dpi surfaces, - // like when we are printing to postscript. + // like when we are printing to postscript or use retina. if (inDesc.devTx != null && !inDesc.devTx.isIdentity()) { try { invDevTx = inDesc.devTx.createInverse(); - } catch (NoninvertibleTransformException e) { + } catch (NoninvertibleTransformException ignored) { // ignored, since device transforms should not be that // complicated, and if they are - there is nothing we can do, // so we won't worry about it. @@ -134,15 +134,13 @@ nativeStrikePtr = 0; } - // the fractional metrics default on our platform is OFF - private boolean useFractionalMetrics() { - return desc.fmHint == SunHints.INTVAL_FRACTIONALMETRICS_ON; - } + @Override public int getNumGlyphs() { return nativeFont.getNumGlyphs(); } + @Override StrikeMetrics getFontMetrics() { if (strikeMetrics == null) { StrikeMetrics metrics = getFontMetrics(getNativeStrikePtr()); @@ -155,74 +153,24 @@ return strikeMetrics; } - float getGlyphAdvance(int glyphCode) { - return getScaledAdvanceForAdvance(getCachedNativeGlyphAdvance(glyphCode)); - } - - float getCodePointAdvance(int cp) { - float advance = getCachedNativeGlyphAdvance(nativeFont.getMapper().charToGlyph(cp)); - - double glyphScaleX = desc.glyphTx.getScaleX(); - double devScaleX = desc.devTx.getScaleX(); - - if (devScaleX == 0) { - glyphScaleX = Math.sqrt(desc.glyphTx.getDeterminant()); - devScaleX = Math.sqrt(desc.devTx.getDeterminant()); - } - - if (devScaleX == 0) { - devScaleX = Double.NaN; // this an undefined graphics state - } - advance = (float) (advance * glyphScaleX / devScaleX); - return useFractionalMetrics() ? advance : Math.round(advance); - } - - // calculate an advance, and round if not using fractional metrics - private float getScaledAdvanceForAdvance(float advance) { - if (invDevTx != null) { - advance *= invDevTx.getScaleX(); - } - advance *= desc.glyphTx.getScaleX(); - return useFractionalMetrics() ? advance : Math.round(advance); + @Override + float getGlyphAdvance(final int glyphCode) { + return getCachedNativeGlyphAdvance(glyphCode); } - Point2D.Float getCharMetrics(char ch) { - return getScaledPointForAdvance(getCachedNativeGlyphAdvance(nativeFont.getMapper().charToGlyph(ch))); - } - - Point2D.Float getGlyphMetrics(int glyphCode) { - return getScaledPointForAdvance(getCachedNativeGlyphAdvance(glyphCode)); + @Override + float getCodePointAdvance(final int cp) { + return getGlyphAdvance(nativeFont.getMapper().charToGlyph(cp)); } - // calculate an advance point, and round if not using fractional metrics - private Point2D.Float getScaledPointForAdvance(float advance) { - Point2D.Float pt = new Point2D.Float(advance, 0); - - if (!desc.glyphTx.isIdentity()) { - return scalePoint(pt); - } - - if (!useFractionalMetrics()) { - pt.x = Math.round(pt.x); - } - return pt; + @Override + Point2D.Float getCharMetrics(final char ch) { + return getGlyphMetrics(nativeFont.getMapper().charToGlyph(ch)); } - private Point2D.Float scalePoint(Point2D.Float pt) { - if (invDevTx != null) { - // transform the point out of the device space first - invDevTx.transform(pt, pt); - } - desc.glyphTx.transform(pt, pt); - pt.x -= desc.glyphTx.getTranslateX(); - pt.y -= desc.glyphTx.getTranslateY(); - - if (!useFractionalMetrics()) { - pt.x = Math.round(pt.x); - pt.y = Math.round(pt.y); - } - - return pt; + @Override + Point2D.Float getGlyphMetrics(final int glyphCode) { + return new Point2D.Float(getGlyphAdvance(glyphCode), 0.0f); } Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) { @@ -414,9 +362,7 @@ private SparseBitShiftingTwoLayerArray secondLayerCache; private HashMap<Integer, Long> generalCache; - public GlyphInfoCache(final Font2D nativeFont, - final FontStrikeDesc desc) - { + GlyphInfoCache(final Font2D nativeFont, final FontStrikeDesc desc) { super(nativeFont, desc); firstLayerCache = new long[FIRST_LAYER_SIZE]; } @@ -527,7 +473,7 @@ final int shift; final int secondLayerLength; - public SparseBitShiftingTwoLayerArray(final int size, final int shift) { + SparseBitShiftingTwoLayerArray(final int size, final int shift) { this.shift = shift; this.cache = new long[1 << shift][]; this.secondLayerLength = size >> shift; @@ -559,6 +505,12 @@ private SparseBitShiftingTwoLayerArray secondLayerCache; private HashMap<Integer, Float> generalCache; + // Empty non private constructor was added because access to this + // class shouldn't be emulated by a synthetic accessor method. + GlyphAdvanceCache() { + super(); + } + public synchronized float get(final int index) { if (index < 0) { if (-index < SECOND_LAYER_SIZE) { @@ -609,9 +561,7 @@ final int shift; final int secondLayerLength; - public SparseBitShiftingTwoLayerArray(final int size, - final int shift) - { + SparseBitShiftingTwoLayerArray(final int size, final int shift) { this.shift = shift; this.cache = new float[1 << shift][]; this.secondLayerLength = size >> shift;
--- a/src/macosx/classes/sun/lwawt/LWToolkit.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/lwawt/LWToolkit.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -37,6 +37,7 @@ import sun.awt.*; import sun.lwawt.macosx.*; +import sun.misc.ThreadGroupUtils; import sun.print.*; public abstract class LWToolkit extends SunToolkit implements Runnable { @@ -66,22 +67,17 @@ protected final void init() { AWTAutoShutdown.notifyToolkitThreadBusy(); - ThreadGroup mainTG = AccessController.doPrivileged( - new PrivilegedAction<ThreadGroup>() { - public ThreadGroup run() { - ThreadGroup currentTG = Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = currentTG.getParent(); - while (parentTG != null) { - currentTG = parentTG; - parentTG = currentTG.getParent(); + ThreadGroup rootTG = AccessController.doPrivileged( + new PrivilegedAction<ThreadGroup>() { + @Override + public ThreadGroup run() { + return ThreadGroupUtils.getRootThreadGroup(); } - return currentTG; - } - } - ); + }); Runtime.getRuntime().addShutdownHook( - new Thread(mainTG, new Runnable() { + new Thread(rootTG, new Runnable() { + @Override public void run() { shutdown(); waitForRunState(STATE_CLEANUP); @@ -89,7 +85,7 @@ }) ); - Thread toolkitThread = new Thread(mainTG, this, "AWT-LW"); + Thread toolkitThread = new Thread(rootTG, this, "AWT-LW"); toolkitThread.setDaemon(true); toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); toolkitThread.start();
--- a/src/macosx/classes/sun/lwawt/macosx/CClipboard.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CClipboard.java Fri May 02 20:39:34 2014 +0100 @@ -53,7 +53,7 @@ } protected void setContentsNative(Transferable contents) { - + FlavorTable flavorMap = getDefaultFlavorTable(); // Don't use delayed Clipboard rendering for the Transferable's data. // If we did that, we would call Transferable.getTransferData on // the Toolkit thread, which is a security hole.
--- a/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java Fri May 02 20:39:34 2014 +0100 @@ -620,8 +620,7 @@ retString[0] = new String(selectedText); }} }, fAwtFocussedComponent); - } catch (InterruptedException ie) { ie.printStackTrace(); } - catch (InvocationTargetException ite) { ite.printStackTrace(); } + } catch (InvocationTargetException ite) { ite.printStackTrace(); } synchronized(retString) { return retString[0]; } } @@ -669,8 +668,7 @@ }} }, fAwtFocussedComponent); - } catch (InterruptedException ie) { ie.printStackTrace(); } - catch (InvocationTargetException ite) { ite.printStackTrace(); } + } catch (InvocationTargetException ite) { ite.printStackTrace(); } synchronized(returnValue) { return returnValue; } } @@ -695,8 +693,7 @@ returnValue[0] = fIMContext.getInsertPositionOffset(); }} }, fAwtFocussedComponent); - } catch (InterruptedException ie) { ie.printStackTrace(); } - catch (InvocationTargetException ite) { ite.printStackTrace(); } + } catch (InvocationTargetException ite) { ite.printStackTrace(); } returnValue[1] = fCurrentTextLength; synchronized(returnValue) { return returnValue; } @@ -743,8 +740,7 @@ } }} }, fAwtFocussedComponent); - } catch (InterruptedException ie) { ie.printStackTrace(); } - catch (InvocationTargetException ite) { ite.printStackTrace(); } + } catch (InvocationTargetException ite) { ite.printStackTrace(); } synchronized(rect) { return rect; } } @@ -764,8 +760,7 @@ insertPositionOffset[0] = fIMContext.getInsertPositionOffset(); }} }, fAwtFocussedComponent); - } catch (InterruptedException ie) { ie.printStackTrace(); } - catch (InvocationTargetException ite) { ite.printStackTrace(); } + } catch (InvocationTargetException ite) { ite.printStackTrace(); } // This bit of gymnastics ensures that the returned location is within the composed text. // If it falls outside that region, the input method will commit the text, which is inconsistent with native
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri May 02 20:39:34 2014 +0100 @@ -931,7 +931,7 @@ //Posting an empty to flush the EventQueue without blocking the main thread } }, target); - } catch (InterruptedException | InvocationTargetException e) { + } catch (InvocationTargetException e) { e.printStackTrace(); } }
--- a/src/macosx/classes/sun/lwawt/macosx/CViewEmbeddedFrame.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CViewEmbeddedFrame.java Fri May 02 20:39:34 2014 +0100 @@ -97,6 +97,6 @@ setVisible(true); } }, this); - } catch (InterruptedException | InvocationTargetException ex) {} + } catch (InvocationTargetException ex) {} } }
--- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Fri May 02 20:39:34 2014 +0100 @@ -424,8 +424,15 @@ } // Intended to be called from the LWCToolkit.m only. - private static void installToolkitThreadNameInJava() { + private static void installToolkitThreadInJava() { Thread.currentThread().setName(CThreading.APPKIT_THREAD_NAME); + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + Thread.currentThread().setContextClassLoader(null); + return null; + } + }); } @Override @@ -528,22 +535,21 @@ // Any selector invoked using ThreadUtilities performOnMainThread will be processed in doAWTRunLoop // The InvocationEvent will call LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual runloop // Does not dispatch native events while in the loop - public static void invokeAndWait(Runnable event, Component component) throws InterruptedException, InvocationTargetException { + public static void invokeAndWait(Runnable runnable, Component component) throws InvocationTargetException { final long mediator = createAWTRunLoopMediator(); - InvocationEvent invocationEvent = - new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event) { - @Override - public void dispatch() { - try { - super.dispatch(); - } finally { - if (mediator != 0) { - stopAWTRunLoop(mediator); + InvocationEvent invocationEvent = AWTAccessor.getInvocationEventAccessor() + .createEvent(component != null ? component : Toolkit.getDefaultToolkit(), + runnable, + new Runnable() { + @Override + public void run() { + if (mediator != 0) { + stopAWTRunLoop(mediator); + } } - } - } - }; + }, + true); if (component != null) { AppContext appContext = SunToolkit.targetToAppContext(component);
--- a/src/macosx/native/sun/awt/LWCToolkit.m Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/native/sun/awt/LWCToolkit.m Fri May 02 20:39:34 2014 +0100 @@ -193,8 +193,8 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); - static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadNameInJava, jc_LWCToolkit, "installToolkitThreadNameInJava", "()V"); - JNFCallStaticVoidMethod(env, jsm_installToolkitThreadNameInJava); + static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); + JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava); }); gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS;
--- a/src/macosx/native/sun/awt/awt.m Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/native/sun/awt/awt.m Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -432,6 +432,16 @@ forceEmbeddedMode = YES; } + JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; + jclass jc_ThreadGroupUtils = (*env)->FindClass(env, "sun/misc/ThreadGroupUtils"); + jmethodID sjm_getRootThreadGroup = (*env)->GetStaticMethodID(env, jc_ThreadGroupUtils, "getRootThreadGroup", "()Ljava/lang/ThreadGroup;"); + jobject rootThreadGroup = (*env)->CallStaticObjectMethod(env, jc_ThreadGroupUtils, sjm_getRootThreadGroup); + [ThreadUtilities setAppkitThreadGroup:(*env)->NewGlobalRef(env, rootThreadGroup)]; + + // The current thread was attached in getJNIEnvUncached. + // Detach it back. It will be reattached later if needed with a proper TG + [ThreadUtilities detachCurrentThread]; + BOOL headless = isHeadless(env); // We need to let Foundation know that this is a multithreaded application, if it isn't already.
--- a/src/macosx/native/sun/font/AWTStrike.h Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/native/sun/font/AWTStrike.h Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 @@ -31,11 +31,12 @@ @interface AWTStrike : NSObject { @public AWTFont * fAWTFont; - CGFloat fSize; + CGFloat fSize; JRSFontRenderingStyle fStyle; - jint fAAStyle; + jint fAAStyle; CGAffineTransform fTx; + CGAffineTransform fDevTx; CGAffineTransform fAltTx; // alternate strike tx used for Sun2D CGAffineTransform fFontTx; }
--- a/src/macosx/native/sun/font/AWTStrike.m Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/native/sun/font/AWTStrike.m Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 @@ -60,6 +60,7 @@ invDevTx.b *= -1; invDevTx.c *= -1; fFontTx = CGAffineTransformConcat(CGAffineTransformConcat(tx, invDevTx), sInverseTX); + fDevTx = CGAffineTransformInvert(invDevTx); // the "font size" is the square root of the determinant of the matrix fSize = sqrt(abs(fFontTx.a * fFontTx.d - fFontTx.b * fFontTx.c)); @@ -143,7 +144,8 @@ { CGSize advance; JNF_COCOA_ENTER(env); - AWTFont *awtFont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont; + AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); + AWTFont *awtFont = awtStrike->fAWTFont; // negative glyph codes are really unicodes, which were placed there by the mapper // to indicate we should use CoreText to substitute the character @@ -151,6 +153,10 @@ const CTFontRef fallback = CTS_CopyCTFallbackFontAndGlyphForJavaGlyphCode(awtFont, glyphCode, &glyph); CTFontGetAdvancesForGlyphs(fallback, kCTFontDefaultOrientation, &glyph, &advance, 1); CFRelease(fallback); + advance = CGSizeApplyAffineTransform(advance, awtStrike->fFontTx); + if (!JRSFontStyleUsesFractionalMetrics(awtStrike->fStyle)) { + advance.width = round(advance.width); + } JNF_COCOA_EXIT(env); return advance.width;
--- a/src/macosx/native/sun/font/CGGlyphImages.m Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/native/sun/font/CGGlyphImages.m Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2013, 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 @@ -455,6 +455,7 @@ #define CGGI_GLYPH_BBOX_PADDING 2.0f static inline GlyphInfo * CGGI_CreateNewGlyphInfoFrom(CGSize advance, CGRect bbox, + const AWTStrike *strike, const CGGI_RenderingMode *mode) { size_t pixelSize = mode->glyphDescriptor->pixelSize; @@ -477,6 +478,12 @@ width = 1; height = 1; } + advance = CGSizeApplyAffineTransform(advance, strike->fFontTx); + if (!JRSFontStyleUsesFractionalMetrics(strike->fStyle)) { + advance.width = round(advance.width); + advance.height = round(advance.height); + } + advance = CGSizeApplyAffineTransform(advance, strike->fDevTx); #ifdef USE_IMAGE_ALIGNED_MEMORY // create separate memory @@ -564,10 +571,10 @@ JRSFontGetBoundingBoxesForGlyphsAndStyle(fallback, &tx, style, &glyph, 1, &bbox); CGSize advance; - JRSFontGetAdvancesForGlyphsAndStyle(fallback, &tx, strike->fStyle, &glyph, 1, &advance); + CTFontGetAdvancesForGlyphs(fallback, kCTFontDefaultOrientation, &glyph, &advance, 1); // create the Sun2D GlyphInfo we are going to strike into - GlyphInfo *info = CGGI_CreateNewGlyphInfoFrom(advance, bbox, mode); + GlyphInfo *info = CGGI_CreateNewGlyphInfoFrom(advance, bbox, strike, mode); // fix the context size, just in case the substituted character is unexpectedly large CGGI_SizeCanvas(canvas, info->width, info->height, mode->cgFontMode); @@ -715,7 +722,7 @@ JRSFontRenderingStyle bboxCGMode = JRSFontAlignStyleForFractionalMeasurement(strike->fStyle); JRSFontGetBoundingBoxesForGlyphsAndStyle((CTFontRef)font->fFont, &tx, bboxCGMode, glyphs, len, bboxes); - JRSFontGetAdvancesForGlyphsAndStyle((CTFontRef)font->fFont, &tx, strike->fStyle, glyphs, len, advances); + CTFontGetAdvancesForGlyphs((CTFontRef)font->fFont, kCTFontDefaultOrientation, glyphs, advances, len); size_t maxWidth = 1; size_t maxHeight = 1; @@ -732,7 +739,7 @@ CGSize advance = advances[i]; CGRect bbox = bboxes[i]; - GlyphInfo *glyphInfo = CGGI_CreateNewGlyphInfoFrom(advance, bbox, mode); + GlyphInfo *glyphInfo = CGGI_CreateNewGlyphInfoFrom(advance, bbox, strike, mode); if (maxWidth < glyphInfo->width) maxWidth = glyphInfo->width; if (maxHeight < glyphInfo->height) maxHeight = glyphInfo->height;
--- a/src/macosx/native/sun/osxapp/ThreadUtilities.h Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/native/sun/osxapp/ThreadUtilities.h Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -127,6 +127,8 @@ + (JNIEnv*)getJNIEnv; + (JNIEnv*)getJNIEnvUncached; ++ (void)detachCurrentThread; ++ (void)setAppkitThreadGroup:(jobject)group; //Wrappers for the corresponding JNFRunLoop methods with a check for main thread + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block;
--- a/src/macosx/native/sun/osxapp/ThreadUtilities.m Wed Apr 30 15:40:34 2014 +0100 +++ b/src/macosx/native/sun/osxapp/ThreadUtilities.m Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -33,23 +33,44 @@ // The following must be named "jvm", as there are extern references to it in AWT JavaVM *jvm = NULL; static JNIEnv *appKitEnv = NULL; +static jobject appkitThreadGroup = NULL; + +inline void attachCurrentThread(void** env) { + if ([NSThread isMainThread]) { + JavaVMAttachArgs args; + args.version = JNI_VERSION_1_4; + args.name = "AppKit Thread"; + args.group = appkitThreadGroup; + (*jvm)->AttachCurrentThreadAsDaemon(jvm, env, &args); + } else { + (*jvm)->AttachCurrentThreadAsDaemon(jvm, env, NULL); + } +} @implementation ThreadUtilities + (JNIEnv*)getJNIEnv { AWT_ASSERT_APPKIT_THREAD; if (appKitEnv == NULL) { - (*jvm)->AttachCurrentThreadAsDaemon(jvm, (void **)&appKitEnv, NULL); + attachCurrentThread((void **)&appKitEnv); } return appKitEnv; } + (JNIEnv*)getJNIEnvUncached { JNIEnv *env = NULL; - (*jvm)->AttachCurrentThreadAsDaemon(jvm, (void **)&env, nil); + attachCurrentThread((void **)&env); return env; } ++ (void)detachCurrentThread { + (*jvm)->DetachCurrentThread(jvm); +} + ++ (void)setAppkitThreadGroup:(jobject)group { + appkitThreadGroup = group; +} + + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block { if ([NSThread isMainThread] && wait == YES) { block();
--- a/src/share/classes/com/sun/jmx/remote/security/SubjectDelegator.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/jmx/remote/security/SubjectDelegator.java Fri May 02 20:39:34 2014 +0100 @@ -35,6 +35,8 @@ import javax.management.remote.SubjectDelegationPermission; import com.sun.jmx.remote.util.CacheMap; +import java.util.ArrayList; +import java.util.Collection; public class SubjectDelegator { private static final int PRINCIPALS_CACHE_SIZE = 10; @@ -53,11 +55,14 @@ boolean removeCallerContext) throws SecurityException { + if (System.getSecurityManager() != null && authenticatedACC == null) { + throw new SecurityException("Illegal AccessControlContext: null"); + } if (principalsCache == null || accCache == null) { principalsCache = - new CacheMap<Subject, Principal[]>(PRINCIPALS_CACHE_SIZE); + new CacheMap<>(PRINCIPALS_CACHE_SIZE); accCache = - new CacheMap<Subject, AccessControlContext>(ACC_CACHE_SIZE); + new CacheMap<>(ACC_CACHE_SIZE); } // Retrieve the principals for the given @@ -101,14 +106,15 @@ // principal in the delegated subject // final Principal[] dp = delegatedPrincipals; + final Collection<Permission> permissions = new ArrayList<>(dp.length); + for(Principal p : dp) { + final String pname = p.getClass().getName() + "." + p.getName(); + permissions.add(new SubjectDelegationPermission(pname)); + } PrivilegedAction<Void> action = new PrivilegedAction<Void>() { public Void run() { - for (int i = 0 ; i < dp.length ; i++) { - final String pname = - dp[i].getClass().getName() + "." + dp[i].getName(); - Permission sdp = - new SubjectDelegationPermission(pname); + for (Permission sdp : permissions) { AccessController.checkPermission(sdp); } return null;
--- a/src/share/classes/com/sun/jndi/dns/DnsClient.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/jndi/dns/DnsClient.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2014, 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 @@ -30,13 +30,14 @@ import java.net.DatagramPacket; import java.net.InetAddress; import java.net.Socket; +import java.security.SecureRandom; import javax.naming.*; import java.util.Collections; import java.util.Map; import java.util.HashMap; -import java.util.Set; -import java.util.HashSet; + +import sun.security.jca.JCAUtil; // Some of this code began life as part of sun.javaos.net.DnsClient // originally by sritchie@eng 1/96. It was first hacked up for JNDI @@ -77,6 +78,8 @@ }; private static final int DEFAULT_PORT = 53; + private static final int TRANSACTION_ID_BOUND = 0x10000; + private static final SecureRandom random = JCAUtil.getSecureRandom(); private InetAddress[] servers; private int[] serverPorts; private int timeout; // initial timeout on UDP queries in ms @@ -85,7 +88,7 @@ private DatagramSocket udpSocket; // Requests sent - private Set<Integer> reqs; + private Map<Integer, ResourceRecord> reqs; // Responses received private Map<Integer, byte[]> resps; @@ -134,7 +137,8 @@ throw ne; } } - reqs = Collections.synchronizedSet(new HashSet<Integer>()); + reqs = Collections.synchronizedMap( + new HashMap<Integer, ResourceRecord>()); resps = Collections.synchronizedMap(new HashMap<Integer, byte[]>()); } @@ -153,10 +157,6 @@ } } - - private int ident = 0; // used to set the msg ID field - private Object identLock = new Object(); - /* * If recursion is true, recursion is requested on the query. * If auth is true, only authoritative responses are accepted; other @@ -167,15 +167,22 @@ throws NamingException { int xid; - synchronized (identLock) { - ident = 0xFFFF & (ident + 1); - xid = ident; - } + Packet pkt; + ResourceRecord collision; + + do { + // Generate a random transaction ID + xid = random.nextInt(TRANSACTION_ID_BOUND); + pkt = makeQueryPacket(fqdn, xid, qclass, qtype, recursion); - // enqueue the outstanding request - reqs.add(xid); - - Packet pkt = makeQueryPacket(fqdn, xid, qclass, qtype, recursion); + // enqueue the outstanding request + synchronized (reqs) { + if ((collision = reqs.put(xid, new ResourceRecord(pkt.getData(), + pkt.length(), Header.HEADER_SIZE, true, false))) != null) { + reqs.put(xid, collision); // revert + } + } + } while (collision != null); Exception caughtException = null; boolean[] doNotRetry = new boolean[servers.length]; @@ -305,11 +312,8 @@ ResourceRecords queryZone(DnsName zone, int qclass, boolean recursion) throws NamingException { - int xid; - synchronized (identLock) { - ident = 0xFFFF & (ident + 1); - xid = ident; - } + int xid = random.nextInt(TRANSACTION_ID_BOUND); + Packet pkt = makeQueryPacket(zone, xid, qclass, ResourceRecord.QTYPE_AXFR, recursion); Exception caughtException = null; @@ -390,6 +394,7 @@ DatagramPacket opkt = new DatagramPacket( pkt.getData(), pkt.length(), server, port); DatagramPacket ipkt = new DatagramPacket(new byte[8000], 8000); + // Packets may only be sent to or received from this server address udpSocket.connect(server, port); int pktTimeout = (timeout * (1 << retry)); try { @@ -524,7 +529,7 @@ "\tResponse Q:" + resps); } byte[] pkt; - if ((pkt = (byte[]) resps.get(xid)) != null) { + if ((pkt = resps.get(xid)) != null) { checkResponseCode(new Header(pkt, pkt.length)); synchronized (queuesLock) { resps.remove(xid); @@ -543,6 +548,9 @@ * Checks the header of an incoming DNS response. * Returns true if it matches the given xid and throws a naming * exception, if appropriate, based on the response code. + * + * Also checks that the domain name, type and class in the response + * match those in the original query. */ private boolean isMatchResponse(byte[] pkt, int xid) throws NamingException { @@ -552,7 +560,7 @@ throw new CommunicationException("DNS error: expecting response"); } - if (!reqs.contains(xid)) { // already received, ignore the response + if (!reqs.containsKey(xid)) { // already received, ignore the response return false; } @@ -561,14 +569,47 @@ if (debug) { dprint("XID MATCH:" + xid); } + checkResponseCode(hdr); + if (!hdr.query && hdr.numQuestions == 1) { - checkResponseCode(hdr); - // remove the response for the xid if received by some other thread. - synchronized (queuesLock) { - resps.remove(xid); - reqs.remove(xid); + ResourceRecord rr = new ResourceRecord(pkt, pkt.length, + Header.HEADER_SIZE, true, false); + + // Retrieve the original query + ResourceRecord query = reqs.get(xid); + int qtype = query.getType(); + int qclass = query.getRrclass(); + DnsName qname = query.getName(); + + // Check that the type/class/name in the query section of the + // response match those in the original query + if ((qtype == ResourceRecord.QTYPE_STAR || + qtype == rr.getType()) && + (qclass == ResourceRecord.QCLASS_STAR || + qclass == rr.getRrclass()) && + qname.equals(rr.getName())) { + + if (debug) { + dprint("MATCH NAME:" + qname + " QTYPE:" + qtype + + " QCLASS:" + qclass); + } + + // Remove the response for the xid if received by some other + // thread. + synchronized (queuesLock) { + resps.remove(xid); + reqs.remove(xid); + } + return true; + + } else { + if (debug) { + dprint("NO-MATCH NAME:" + qname + " QTYPE:" + qtype + + " QCLASS:" + qclass); + } + } } - return true; + return false; } // @@ -577,7 +618,7 @@ // enqueue only the first response, responses for retries are ignored. // synchronized (queuesLock) { - if (reqs.contains(hdr.xid)) { // enqueue only the first response + if (reqs.containsKey(hdr.xid)) { // enqueue only the first response resps.put(hdr.xid, pkt); } }
--- a/src/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, 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 @@ -25,6 +25,10 @@ package com.sun.jndi.ldap; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Vector; import javax.naming.*; import javax.naming.directory.*; @@ -34,6 +38,8 @@ final class LdapBindingEnumeration extends LdapNamingEnumeration { + private final AccessControlContext acc = AccessController.getContext(); + LdapBindingEnumeration(LdapCtx homeCtx, LdapResult answer, Name remain, Continuation cont) throws NamingException { @@ -41,7 +47,7 @@ } protected NameClassPair - createItem(String dn, Attributes attrs, Vector respCtls) + createItem(String dn, final Attributes attrs, Vector respCtls) throws NamingException { Object obj = null; @@ -49,7 +55,16 @@ if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) { // serialized object or object reference - obj = Obj.decodeObject(attrs); + try { + obj = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + @Override + public Object run() throws NamingException { + return Obj.decodeObject(attrs); + } + }, acc); + } catch (PrivilegedActionException e) { + throw (NamingException)e.getException(); + } } if (obj == null) { // DirContext object
--- a/src/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, 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 @@ -25,6 +25,10 @@ package com.sun.jndi.ldap; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.Vector; import javax.naming.*; import javax.naming.directory.*; @@ -39,6 +43,8 @@ private Name startName; // prefix of names of search results private LdapCtx.SearchArgs searchArgs = null; + private final AccessControlContext acc = AccessController.getContext(); + LdapSearchEnumeration(LdapCtx homeCtx, LdapResult search_results, String starter, LdapCtx.SearchArgs args, Continuation cont) throws NamingException { @@ -53,7 +59,7 @@ } protected NameClassPair - createItem(String dn, Attributes attrs, Vector respCtls) + createItem(String dn, final Attributes attrs, Vector respCtls) throws NamingException { Object obj = null; @@ -110,8 +116,16 @@ if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) { // Entry contains Java-object attributes (ser/ref object) // serialized object or object reference - obj = Obj.decodeObject(attrs); - + try { + obj = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + @Override + public Object run() throws NamingException { + return Obj.decodeObject(attrs); + } + }, acc); + } catch (PrivilegedActionException e) { + throw (NamingException)e.getException(); + } } if (obj == null) { obj = new LdapCtx(homeCtx, dn);
--- a/src/share/classes/com/sun/media/sound/JDK13Services.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/media/sound/JDK13Services.java Fri May 02 20:39:34 2014 +0100 @@ -25,27 +25,33 @@ package com.sun.media.sound; +import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Properties; import javax.sound.midi.Receiver; import javax.sound.midi.Sequencer; import javax.sound.midi.Synthesizer; import javax.sound.midi.Transmitter; +import javax.sound.midi.spi.MidiDeviceProvider; +import javax.sound.midi.spi.MidiFileReader; +import javax.sound.midi.spi.MidiFileWriter; +import javax.sound.midi.spi.SoundbankReader; import javax.sound.sampled.Clip; import javax.sound.sampled.Port; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.TargetDataLine; +import javax.sound.sampled.spi.AudioFileReader; +import javax.sound.sampled.spi.AudioFileWriter; +import javax.sound.sampled.spi.FormatConversionProvider; +import javax.sound.sampled.spi.MixerProvider; /** - * JDK13Services uses the Service class in JDK 1.3 - * to discover a list of service providers installed - * in the system. - * + * JDK13Services uses the Service class in JDK 1.3 to discover a list of service + * providers installed in the system. + * <p> * This class is public because it is called from javax.sound.midi.MidiSystem * and javax.sound.sampled.AudioSystem. The alternative would be to make * JSSecurityManager public, which is considered worse. @@ -54,80 +60,55 @@ */ public final class JDK13Services { - /** The default for the length of the period to hold the cache. - This value is given in milliseconds. It is equivalent to - 1 minute. - */ - private static final long DEFAULT_CACHING_PERIOD = 60000; - - /** Filename of the properties file for default provider properties. - This file is searched in the subdirectory "lib" of the JRE directory - (this behaviour is hardcoded). - */ + /** + * Filename of the properties file for default provider properties. This + * file is searched in the subdirectory "lib" of the JRE directory (this + * behaviour is hardcoded). + */ private static final String PROPERTIES_FILENAME = "sound.properties"; - /** Cache for the providers. - Class objects of the provider type (MixerProvider, MidiDeviceProvider - ...) are used as keys. The values are instances of ProviderCache. - */ - private static final Map providersCacheMap = new HashMap(); - - - /** The length of the period to hold the cache. - This value is given in milliseconds. - */ - private static long cachingPeriod = DEFAULT_CACHING_PERIOD; - - /** Properties loaded from the properties file for default provider - properties. - */ + /** + * Properties loaded from the properties file for default provider + * properties. + */ private static Properties properties; - - /** Private, no-args constructor to ensure against instantiation. + /** + * Private, no-args constructor to ensure against instantiation. */ private JDK13Services() { } - - /** Set the period provider lists are cached. - This method is only intended for testing. + /** + * Obtains a List containing installed instances of the providers for the + * requested service. The returned List is immutable. + * + * @param serviceClass The type of providers requested. This should be one + * of AudioFileReader.class, AudioFileWriter.class, + * FormatConversionProvider.class, MixerProvider.class, + * MidiDeviceProvider.class, MidiFileReader.class, + * MidiFileWriter.class or SoundbankReader.class. + * + * @return A List of providers of the requested type. This List is + * immutable. */ - public static void setCachingPeriod(int seconds) { - cachingPeriod = seconds * 1000L; + public static List<?> getProviders(final Class<?> serviceClass) { + final List<?> providers; + if (!MixerProvider.class.equals(serviceClass) + && !FormatConversionProvider.class.equals(serviceClass) + && !AudioFileReader.class.equals(serviceClass) + && !AudioFileWriter.class.equals(serviceClass) + && !MidiDeviceProvider.class.equals(serviceClass) + && !SoundbankReader.class.equals(serviceClass) + && !MidiFileWriter.class.equals(serviceClass) + && !MidiFileReader.class.equals(serviceClass)) { + providers = new ArrayList<>(0); + } else { + providers = JSSecurityManager.getProviders(serviceClass); + } + return Collections.unmodifiableList(providers); } - - /** Obtains a List containing installed instances of the - providers for the requested service. - The List of providers is cached for the period of time given by - {@link #cachingPeriod cachingPeriod}. During this period, the same - List instance is returned for the same type of provider. After this - period, a new instance is constructed and returned. The returned - List is immutable. - @param serviceClass The type of providers requested. This should be one - of AudioFileReader.class, AudioFileWriter.class, - FormatConversionProvider.class, MixerProvider.class, - MidiDeviceProvider.class, MidiFileReader.class, MidiFileWriter.class or - SoundbankReader.class. - @return A List of providers of the requested type. This List is - immutable. - */ - public static synchronized List getProviders(Class serviceClass) { - ProviderCache cache = (ProviderCache) providersCacheMap.get(serviceClass); - if (cache == null) { - cache = new ProviderCache(); - providersCacheMap.put(serviceClass, cache); - } - if (cache.providers == null || - System.currentTimeMillis() > cache.lastUpdate + cachingPeriod) { - cache.providers = Collections.unmodifiableList(JSSecurityManager.getProviders(serviceClass)); - cache.lastUpdate = System.currentTimeMillis(); - } - return cache.providers; - } - - /** Obtain the provider class name part of a default provider property. @param typeClass The type of the default provider property. This should be one of Receiver.class, Transmitter.class, Sequencer.class, @@ -219,14 +200,4 @@ } return properties; } - - // INNER CLASSES - - private static class ProviderCache { - // System time of the last update in milliseconds. - public long lastUpdate; - - // The providers. - public List providers; - } }
--- a/src/share/classes/com/sun/media/sound/JSSecurityManager.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/media/sound/JSSecurityManager.java Fri May 02 20:39:34 2014 +0100 @@ -187,7 +187,7 @@ return thread; } - static List getProviders(final Class providerClass) { + static synchronized List getProviders(final Class providerClass) { List p = new ArrayList(); // Service.providers(Class) just creates "lazy" iterator instance, // so it doesn't require do be called from privileged section
--- a/src/share/classes/com/sun/naming/internal/ResourceManager.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/naming/internal/ResourceManager.java Fri May 02 20:39:34 2014 +0100 @@ -69,6 +69,14 @@ private static final String JRELIB_PROPERTY_FILE_NAME = "jndi.properties"; /* + * Internal environment property, that when set to "true", disables + * application resource files lookup to prevent recursion issues + * when validating signed JARs. + */ + private static final String DISABLE_APP_RESOURCE_FILES = + "com.sun.naming.disable.app.resource.files"; + + /* * The standard JNDI properties that specify colon-separated lists. */ private static final String[] listProperties = { @@ -218,6 +226,13 @@ } } + // Return without merging if application resource files lookup + // is disabled. + String disableAppRes = (String)env.get(DISABLE_APP_RESOURCE_FILES); + if (disableAppRes != null && disableAppRes.equalsIgnoreCase("true")) { + return env; + } + // Merge the above with the values read from all application // resource files. Colon-separated lists are concatenated. mergeTables(env, getApplicationResources());
--- a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2013, 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 @@ -37,6 +37,7 @@ import javax.sql.rowset.serial.*; import com.sun.rowset.internal.*; import com.sun.rowset.providers.*; +import sun.reflect.misc.ReflectUtil; /** * The standard implementation of the <code>CachedRowSet</code> interface. @@ -2963,13 +2964,9 @@ // create new instance of the class SQLData obj = null; try { - obj = (SQLData)c.newInstance(); - } catch (java.lang.InstantiationException ex) { - throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(), - ex.getMessage())); - } catch (java.lang.IllegalAccessException ex) { - throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(), - ex.getMessage())); + obj = (SQLData) ReflectUtil.newInstance(c); + } catch(Exception ex) { + throw new SQLException("Unable to Instantiate: ", ex); } // get the attributes from the struct Object attribs[] = s.getAttributes(map); @@ -5714,13 +5711,9 @@ // create new instance of the class SQLData obj = null; try { - obj = (SQLData)c.newInstance(); - } catch (java.lang.InstantiationException ex) { - throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(), - ex.getMessage())); - } catch (java.lang.IllegalAccessException ex) { - throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(), - ex.getMessage())); + obj = (SQLData) ReflectUtil.newInstance(c); + } catch(Exception ex) { + throw new SQLException("Unable to Instantiate: ", ex); } // get the attributes from the struct Object attribs[] = s.getAttributes(map);
--- a/src/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/com/sun/rowset/internal/CachedRowSetWriter.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2013, 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 @@ -39,6 +39,7 @@ import javax.sql.rowset.serial.SerialClob; import javax.sql.rowset.serial.SerialStruct; import javax.sql.rowset.spi.*; +import sun.reflect.misc.ReflectUtil; /** @@ -578,13 +579,9 @@ // create new instance of the class SQLData obj = null; try { - obj = (SQLData)c.newInstance(); - } catch (java.lang.InstantiationException ex) { - throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(), - ex.getMessage())); - } catch (java.lang.IllegalAccessException ex) { - throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(), - ex.getMessage())); + obj = (SQLData)ReflectUtil.newInstance(c); + } catch (Exception ex) { + throw new SQLException("Unable to Instantiate: ", ex); } // get the attributes from the struct Object attribs[] = s.getAttributes(map);
--- a/src/share/classes/java/awt/EventQueue.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/awt/EventQueue.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, 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 @@ -1043,11 +1043,11 @@ t.setContextClassLoader(classLoader); t.setPriority(Thread.NORM_PRIORITY + 1); t.setDaemon(false); + AWTAutoShutdown.getInstance().notifyThreadBusy(t); return t; } } ); - AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread); dispatchThread.start(); } } finally { @@ -1139,6 +1139,10 @@ if (entry.event instanceof SentEvent) { ((SentEvent)entry.event).dispose(); } + if (entry.event instanceof InvocationEvent) { + AWTAccessor.getInvocationEventAccessor() + .dispose((InvocationEvent)entry.event); + } if (prev == null) { queues[i].head = entry.next; } else {
--- a/src/share/classes/java/awt/Toolkit.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/awt/Toolkit.java Fri May 02 20:39:34 2014 +0100 @@ -2559,26 +2559,30 @@ public void firePropertyChange(final PropertyChangeEvent evt) { Object oldValue = evt.getOldValue(); Object newValue = evt.getNewValue(); + String propertyName = evt.getPropertyName(); if (oldValue != null && newValue != null && oldValue.equals(newValue)) { return; } + Runnable updater = new Runnable() { + public void run() { + PropertyChangeSupport pcs = (PropertyChangeSupport) + AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); + if (null != pcs) { + pcs.firePropertyChange(evt); + } + } + }; + final AppContext currentAppContext = AppContext.getAppContext(); for (AppContext appContext : AppContext.getAppContexts()) { if (null == appContext || appContext.isDisposed()) { continue; } - final PeerEvent e = new PeerEvent(source, - new Runnable() { - @Override - public void run() { - PropertyChangeSupport pcs = (PropertyChangeSupport) - AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); - if (null != pcs) { - pcs.firePropertyChange(evt); - } - } - }, - PeerEvent.ULTIMATE_PRIORITY_EVENT); - SunToolkit.postEvent(appContext, e); + if (currentAppContext == appContext) { + updater.run(); + } else { + final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT); + SunToolkit.postEvent(appContext, e); + } } } }
--- a/src/share/classes/java/awt/datatransfer/SystemFlavorMap.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/awt/datatransfer/SystemFlavorMap.java Fri May 02 20:39:34 2014 +0100 @@ -45,8 +45,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; +import sun.awt.AppContext; import sun.awt.datatransfer.DataTransferer; /** @@ -72,10 +72,7 @@ */ private static String JavaMIME = "JAVA_DATAFLAVOR:"; - /** - * System singleton which maps a thread's ClassLoader to a SystemFlavorMap. - */ - private static final WeakHashMap flavorMaps = new WeakHashMap(); + private static final Object FLAVOR_MAP_KEY = new Object(); /** * Copied from java.util.Properties. @@ -184,22 +181,12 @@ * Returns the default FlavorMap for this thread's ClassLoader. */ public static FlavorMap getDefaultFlavorMap() { - ClassLoader contextClassLoader = - Thread.currentThread().getContextClassLoader(); - if (contextClassLoader == null) { - contextClassLoader = ClassLoader.getSystemClassLoader(); + AppContext context = AppContext.getAppContext(); + FlavorMap fm = (FlavorMap) context.get(FLAVOR_MAP_KEY); + if (fm == null) { + fm = new SystemFlavorMap(); + context.put(FLAVOR_MAP_KEY, fm); } - - FlavorMap fm; - - synchronized(flavorMaps) { - fm = (FlavorMap)flavorMaps.get(contextClassLoader); - if (fm == null) { - fm = new SystemFlavorMap(); - flavorMaps.put(contextClassLoader, fm); - } - } - return fm; } @@ -240,26 +227,11 @@ } }); - BufferedReader flavormapURL = + String url = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction<BufferedReader>() { - public BufferedReader run() { - String url = Toolkit.getProperty("AWT.DnD.flavorMapFileURL", null); - - if (url == null) { - return null; - } - - try { - return new BufferedReader - (new InputStreamReader - (new URL(url).openStream(), "ISO-8859-1")); - } catch (MalformedURLException e) { - System.err.println("MalformedURLException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); - } catch (IOException e) { - System.err.println("IOException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); - } - return null; + new java.security.PrivilegedAction<String>() { + public String run() { + return Toolkit.getProperty("AWT.DnD.flavorMapFileURL", null); } }); @@ -271,6 +243,19 @@ } } + BufferedReader flavormapURL = null; + if (url != null) { + try { + flavormapURL = new BufferedReader(new InputStreamReader(new URL(url).openStream(), "ISO-8859-1")); + } catch (MalformedURLException e) { + System.err.println("MalformedURLException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); + } catch (IOException e) { + System.err.println("IOException:" + e + " while reading AWT.DnD.flavorMapFileURL:" + url); + } catch (SecurityException e) { + // ignored + } + } + if (flavormapURL != null) { try { parseAndStoreReader(flavormapURL);
--- a/src/share/classes/java/awt/event/InvocationEvent.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/awt/event/InvocationEvent.java Fri May 02 20:39:34 2014 +0100 @@ -25,6 +25,8 @@ package java.awt.event; +import sun.awt.AWTAccessor; + import java.awt.ActiveEvent; import java.awt.AWTEvent; @@ -56,6 +58,20 @@ */ public class InvocationEvent extends AWTEvent implements ActiveEvent { + static { + AWTAccessor.setInvocationEventAccessor(new AWTAccessor.InvocationEventAccessor() { + @Override + public void dispose(InvocationEvent invocationEvent) { + invocationEvent.finishedDispatching(false); + } + @Override + public InvocationEvent createEvent(Object source, Runnable runnable, Runnable listener, + boolean catchThrowables) { + return new InvocationEvent(source, runnable, listener, catchThrowables); + } + }); + } + /** * Marks the first integer id for the range of invocation event ids. */ @@ -85,6 +101,14 @@ protected Object notifier; /** + * The (potentially null) Runnable whose run() method will be called + * immediately after the event was dispatched or disposed. + * + * @see #isDispatched + */ + private final Runnable listener; + + /** * Indicates whether the <code>run()</code> method of the <code>runnable</code> * was executed or not. * @@ -147,7 +171,7 @@ * @see #InvocationEvent(Object, Runnable, Object, boolean) */ public InvocationEvent(Object source, Runnable runnable) { - this(source, runnable, null, false); + this(source, INVOCATION_DEFAULT, runnable, null, null, false); } /** @@ -185,7 +209,39 @@ */ public InvocationEvent(Object source, Runnable runnable, Object notifier, boolean catchThrowables) { - this(source, INVOCATION_DEFAULT, runnable, notifier, catchThrowables); + this(source, INVOCATION_DEFAULT, runnable, notifier, null, catchThrowables); + } + + /** + * Constructs an <code>InvocationEvent</code> with the specified + * source which will execute the runnable's <code>run</code> + * method when dispatched. If listener is non-<code>null</code>, + * <code>listener.run()</code> will be called immediately after + * <code>run</code> has returned, thrown an exception or the event + * was disposed. + * <p>This method throws an <code>IllegalArgumentException</code> + * if <code>source</code> is <code>null</code>. + * + * @param source The <code>Object</code> that originated + * the event + * @param runnable The <code>Runnable</code> whose + * <code>run</code> method will be + * executed + * @param listener The <code>Runnable</code>Runnable whose + * <code>run()</code> method will be called + * after the {@code InvocationEvent} + * was dispatched or disposed + * @param catchThrowables Specifies whether <code>dispatch</code> + * should catch Throwable when executing + * the <code>Runnable</code>'s <code>run</code> + * method, or should instead propagate those + * Throwables to the EventDispatchThread's + * dispatch loop + * @throws IllegalArgumentException if <code>source</code> is null + */ + private InvocationEvent(Object source, Runnable runnable, Runnable listener, + boolean catchThrowables) { + this(source, INVOCATION_DEFAULT, runnable, null, listener, catchThrowables); } /** @@ -221,13 +277,18 @@ */ protected InvocationEvent(Object source, int id, Runnable runnable, Object notifier, boolean catchThrowables) { + this(source, id, runnable, notifier, null, catchThrowables); + } + + private InvocationEvent(Object source, int id, Runnable runnable, + Object notifier, Runnable listener, boolean catchThrowables) { super(source, id); this.runnable = runnable; this.notifier = notifier; + this.listener = listener; this.catchExceptions = catchThrowables; this.when = System.currentTimeMillis(); } - /** * Executes the Runnable's <code>run()</code> method and notifies the * notifier (if any) when <code>run()</code> has returned or thrown an exception. @@ -251,13 +312,7 @@ runnable.run(); } } finally { - dispatched = true; - - if (notifier != null) { - synchronized (notifier) { - notifier.notifyAll(); - } - } + finishedDispatching(true); } } @@ -331,6 +386,25 @@ } /** + * Called when the event was dispatched or disposed + * @param dispatched true if the event was dispatched + * false if the event was disposed + */ + private void finishedDispatching(boolean dispatched) { + this.dispatched = dispatched; + + if (notifier != null) { + synchronized (notifier) { + notifier.notifyAll(); + } + } + + if (listener != null) { + listener.run(); + } + } + + /** * Returns a parameter string identifying this event. * This method is useful for event-logging and for debugging. *
--- a/src/share/classes/java/lang/Thread.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/lang/Thread.java Fri May 02 20:39:34 2014 +0100 @@ -366,6 +366,8 @@ throw new NullPointerException("name cannot be null"); } + this.name = name.toCharArray(); + Thread parent = currentThread(); SecurityManager security = System.getSecurityManager(); if (g == null) { @@ -402,7 +404,6 @@ this.group = g; this.daemon = parent.isDaemon(); this.priority = parent.getPriority(); - this.name = name.toCharArray(); if (security == null || isCCLOverridden(parent.getClass())) this.contextClassLoader = parent.getContextClassLoader(); else
--- a/src/share/classes/java/lang/invoke/BoundMethodHandle.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/lang/invoke/BoundMethodHandle.java Fri May 02 20:39:34 2014 +0100 @@ -140,7 +140,7 @@ * Return the {@link SpeciesData} instance representing this BMH species. All subclasses must provide a * static field containing this value, and they must accordingly implement this method. */ - protected abstract SpeciesData speciesData(); + /*non-public*/ abstract SpeciesData speciesData(); @Override final Object internalProperties() { @@ -156,7 +156,7 @@ return Arrays.asList(boundValues); } - public final Object arg(int i) { + /*non-public*/ final Object arg(int i) { try { switch (speciesData().fieldType(i)) { case 'L': return argL(i); @@ -170,22 +170,22 @@ } throw new InternalError("unexpected type: " + speciesData().types+"."+i); } - public final Object argL(int i) throws Throwable { return speciesData().getters[i].invokeBasic(this); } - public final int argI(int i) throws Throwable { return (int) speciesData().getters[i].invokeBasic(this); } - public final float argF(int i) throws Throwable { return (float) speciesData().getters[i].invokeBasic(this); } - public final double argD(int i) throws Throwable { return (double) speciesData().getters[i].invokeBasic(this); } - public final long argJ(int i) throws Throwable { return (long) speciesData().getters[i].invokeBasic(this); } + /*non-public*/ final Object argL(int i) throws Throwable { return speciesData().getters[i].invokeBasic(this); } + /*non-public*/ final int argI(int i) throws Throwable { return (int) speciesData().getters[i].invokeBasic(this); } + /*non-public*/ final float argF(int i) throws Throwable { return (float) speciesData().getters[i].invokeBasic(this); } + /*non-public*/ final double argD(int i) throws Throwable { return (double) speciesData().getters[i].invokeBasic(this); } + /*non-public*/ final long argJ(int i) throws Throwable { return (long) speciesData().getters[i].invokeBasic(this); } // // cloning API // - public abstract BoundMethodHandle clone(MethodType mt, LambdaForm lf) throws Throwable; - public abstract BoundMethodHandle cloneExtendL(MethodType mt, LambdaForm lf, Object narg) throws Throwable; - public abstract BoundMethodHandle cloneExtendI(MethodType mt, LambdaForm lf, int narg) throws Throwable; - public abstract BoundMethodHandle cloneExtendJ(MethodType mt, LambdaForm lf, long narg) throws Throwable; - public abstract BoundMethodHandle cloneExtendF(MethodType mt, LambdaForm lf, float narg) throws Throwable; - public abstract BoundMethodHandle cloneExtendD(MethodType mt, LambdaForm lf, double narg) throws Throwable; + /*non-public*/ abstract BoundMethodHandle clone(MethodType mt, LambdaForm lf) throws Throwable; + /*non-public*/ abstract BoundMethodHandle cloneExtendL(MethodType mt, LambdaForm lf, Object narg) throws Throwable; + /*non-public*/ abstract BoundMethodHandle cloneExtendI(MethodType mt, LambdaForm lf, int narg) throws Throwable; + /*non-public*/ abstract BoundMethodHandle cloneExtendJ(MethodType mt, LambdaForm lf, long narg) throws Throwable; + /*non-public*/ abstract BoundMethodHandle cloneExtendF(MethodType mt, LambdaForm lf, float narg) throws Throwable; + /*non-public*/ abstract BoundMethodHandle cloneExtendD(MethodType mt, LambdaForm lf, double narg) throws Throwable; // The following is a grossly irregular hack: @Override MethodHandle reinvokerTarget() { @@ -203,39 +203,39 @@ private // make it private to force users to access the enclosing class first static final class Species_L extends BoundMethodHandle { final Object argL0; - public Species_L(MethodType mt, LambdaForm lf, Object argL0) { + /*non-public*/ Species_L(MethodType mt, LambdaForm lf, Object argL0) { super(mt, lf); this.argL0 = argL0; } // The following is a grossly irregular hack: @Override MethodHandle reinvokerTarget() { return (MethodHandle) argL0; } @Override - public SpeciesData speciesData() { + /*non-public*/ SpeciesData speciesData() { return SPECIES_DATA; } - public static final SpeciesData SPECIES_DATA = SpeciesData.getForClass("L", Species_L.class); + /*non-public*/ static final SpeciesData SPECIES_DATA = SpeciesData.getForClass("L", Species_L.class); @Override - public final BoundMethodHandle clone(MethodType mt, LambdaForm lf) throws Throwable { + /*non-public*/ final BoundMethodHandle clone(MethodType mt, LambdaForm lf) throws Throwable { return new Species_L(mt, lf, argL0); } @Override - public final BoundMethodHandle cloneExtendL(MethodType mt, LambdaForm lf, Object narg) throws Throwable { + /*non-public*/ final BoundMethodHandle cloneExtendL(MethodType mt, LambdaForm lf, Object narg) throws Throwable { return (BoundMethodHandle) SPECIES_DATA.extendWithIndex(INDEX_L).constructor[0].invokeBasic(mt, lf, argL0, narg); } @Override - public final BoundMethodHandle cloneExtendI(MethodType mt, LambdaForm lf, int narg) throws Throwable { + /*non-public*/ final BoundMethodHandle cloneExtendI(MethodType mt, LambdaForm lf, int narg) throws Throwable { return (BoundMethodHandle) SPECIES_DATA.extendWithIndex(INDEX_I).constructor[0].invokeBasic(mt, lf, argL0, narg); } @Override - public final BoundMethodHandle cloneExtendJ(MethodType mt, LambdaForm lf, long narg) throws Throwable { + /*non-public*/ final BoundMethodHandle cloneExtendJ(MethodType mt, LambdaForm lf, long narg) throws Throwable { return (BoundMethodHandle) SPECIES_DATA.extendWithIndex(INDEX_J).constructor[0].invokeBasic(mt, lf, argL0, narg); } @Override - public final BoundMethodHandle cloneExtendF(MethodType mt, LambdaForm lf, float narg) throws Throwable { + /*non-public*/ final BoundMethodHandle cloneExtendF(MethodType mt, LambdaForm lf, float narg) throws Throwable { return (BoundMethodHandle) SPECIES_DATA.extendWithIndex(INDEX_F).constructor[0].invokeBasic(mt, lf, argL0, narg); } @Override - public final BoundMethodHandle cloneExtendD(MethodType mt, LambdaForm lf, double narg) throws Throwable { + /*non-public*/ final BoundMethodHandle cloneExtendD(MethodType mt, LambdaForm lf, double narg) throws Throwable { return (BoundMethodHandle) SPECIES_DATA.extendWithIndex(INDEX_D).constructor[0].invokeBasic(mt, lf, argL0, narg); } } @@ -338,10 +338,10 @@ final MethodHandle[] getters; final SpeciesData[] extensions; - public int fieldCount() { + /*non-public*/ int fieldCount() { return types.length(); } - public char fieldType(int i) { + /*non-public*/ char fieldType(int i) { return types.charAt(i); } @@ -546,30 +546,30 @@ * final Object argL0; * final Object argL1; * final int argI2; - * public Species_LLI(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) { + * Species_LLI(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) { * super(mt, lf); * this.argL0 = argL0; * this.argL1 = argL1; * this.argI2 = argI2; * } - * public final SpeciesData speciesData() { return SPECIES_DATA; } - * public static final SpeciesData SPECIES_DATA = SpeciesData.getForClass("LLI", Species_LLI.class); - * public final BoundMethodHandle clone(MethodType mt, LambdaForm lf) { + * final SpeciesData speciesData() { return SPECIES_DATA; } + * static final SpeciesData SPECIES_DATA = SpeciesData.getForClass("LLI", Species_LLI.class); + * final BoundMethodHandle clone(MethodType mt, LambdaForm lf) { * return SPECIES_DATA.constructor[0].invokeBasic(mt, lf, argL0, argL1, argI2); * } - * public final BoundMethodHandle cloneExtendL(MethodType mt, LambdaForm lf, Object narg) { + * final BoundMethodHandle cloneExtendL(MethodType mt, LambdaForm lf, Object narg) { * return SPECIES_DATA.extendWithIndex(INDEX_L).constructor[0].invokeBasic(mt, lf, argL0, argL1, argI2, narg); * } - * public final BoundMethodHandle cloneExtendI(MethodType mt, LambdaForm lf, int narg) { + * final BoundMethodHandle cloneExtendI(MethodType mt, LambdaForm lf, int narg) { * return SPECIES_DATA.extendWithIndex(INDEX_I).constructor[0].invokeBasic(mt, lf, argL0, argL1, argI2, narg); * } - * public final BoundMethodHandle cloneExtendJ(MethodType mt, LambdaForm lf, long narg) { + * final BoundMethodHandle cloneExtendJ(MethodType mt, LambdaForm lf, long narg) { * return SPECIES_DATA.extendWithIndex(INDEX_J).constructor[0].invokeBasic(mt, lf, argL0, argL1, argI2, narg); * } - * public final BoundMethodHandle cloneExtendF(MethodType mt, LambdaForm lf, float narg) { + * final BoundMethodHandle cloneExtendF(MethodType mt, LambdaForm lf, float narg) { * return SPECIES_DATA.extendWithIndex(INDEX_F).constructor[0].invokeBasic(mt, lf, argL0, argL1, argI2, narg); * } - * public final BoundMethodHandle cloneExtendD(MethodType mt, LambdaForm lf, double narg) { + * final BoundMethodHandle cloneExtendD(MethodType mt, LambdaForm lf, double narg) { * return SPECIES_DATA.extendWithIndex(INDEX_D).constructor[0].invokeBasic(mt, lf, argL0, argL1, argI2, narg); * } * } @@ -583,11 +583,12 @@ final String className = SPECIES_PREFIX_PATH + types; final String sourceFile = SPECIES_PREFIX_NAME + types; - cw.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, BMH, null); + final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC + cw.visit(V1_6, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, BMH, null); cw.visitSource(sourceFile, null); // emit static types and SPECIES_DATA fields - cw.visitField(ACC_PUBLIC + ACC_STATIC, "SPECIES_DATA", SPECIES_DATA_SIG, null, null).visitEnd(); + cw.visitField(NOT_ACC_PUBLIC + ACC_STATIC, "SPECIES_DATA", SPECIES_DATA_SIG, null, null).visitEnd(); // emit bound argument fields for (int i = 0; i < types.length(); ++i) { @@ -600,7 +601,7 @@ MethodVisitor mv; // emit constructor - mv = cw.visitMethod(ACC_PUBLIC, "<init>", makeSignature(types, true), null, null); + mv = cw.visitMethod(NOT_ACC_PUBLIC, "<init>", makeSignature(types, true), null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); @@ -624,7 +625,7 @@ mv.visitEnd(); // emit implementation of reinvokerTarget() - mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "reinvokerTarget", "()" + MH_SIG, null, null); + mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "reinvokerTarget", "()" + MH_SIG, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "argL0", JLO_SIG); @@ -634,7 +635,7 @@ mv.visitEnd(); // emit implementation of speciesData() - mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "speciesData", MYSPECIES_DATA_SIG, null, null); + mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "speciesData", MYSPECIES_DATA_SIG, null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, className, "SPECIES_DATA", SPECIES_DATA_SIG); mv.visitInsn(ARETURN); @@ -642,7 +643,7 @@ mv.visitEnd(); // emit clone() - mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "clone", makeSignature("", false), null, E_THROWABLE); + mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "clone", makeSignature("", false), null, E_THROWABLE); mv.visitCode(); // return speciesData().constructor[0].invokeBasic(mt, lf, argL0, ...) // obtain constructor @@ -665,7 +666,7 @@ // for each type, emit cloneExtendT() for (Class<?> c : TYPES) { char t = Wrapper.basicTypeChar(c); - mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "cloneExtend" + t, makeSignature(String.valueOf(t), false), null, E_THROWABLE); + mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "cloneExtend" + t, makeSignature(String.valueOf(t), false), null, E_THROWABLE); mv.visitCode(); // return SPECIES_DATA.extendWithIndex(extensionIndex(t)).constructor[0].invokeBasic(mt, lf, argL0, ..., narg) // obtain constructor @@ -692,7 +693,7 @@ } // emit class initializer - mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", VOID_SIG, null, null); + mv = cw.visitMethod(NOT_ACC_PUBLIC | ACC_STATIC, "<clinit>", VOID_SIG, null, null); mv.visitCode(); mv.visitLdcInsn(types); mv.visitLdcInsn(Type.getObjectType(className));
--- a/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java Fri May 02 20:39:34 2014 +0100 @@ -289,8 +289,9 @@ * Set up class file generation. */ private void classFilePrologue() { + final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES); - cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, className, null, superName, null); + cw.visit(Opcodes.V1_6, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, className, null, superName, null); cw.visitSource(sourceFile, null); String invokerDesc = invokerType.toMethodDescriptorString();
--- a/src/share/classes/java/lang/invoke/MethodHandles.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/lang/invoke/MethodHandles.java Fri May 02 20:39:34 2014 +0100 @@ -1616,6 +1616,7 @@ */ public static MethodHandle permuteArguments(MethodHandle target, MethodType newType, int... reorder) { + reorder = reorder.clone(); checkReorder(reorder, newType, target.type()); return target.permuteArguments(newType, reorder); } @@ -1810,6 +1811,7 @@ throw newIllegalArgumentException("no argument type to remove"); ArrayList<Class<?>> ptypes = new ArrayList<>(oldType.parameterList()); ptypes.addAll(pos, valueTypes); + if (ptypes.size() != inargs) throw newIllegalArgumentException("valueTypes"); MethodType newType = MethodType.methodType(oldType.returnType(), ptypes); return target.dropArguments(newType, pos, dropped); }
--- a/src/share/classes/java/util/ServiceLoader.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/util/ServiceLoader.java Fri May 02 20:39:34 2014 +0100 @@ -375,7 +375,7 @@ return p; } catch (Throwable x) { fail(service, - "Provider " + cn + " could not be instantiated: " + x, + "Provider " + cn + " could not be instantiated", x); } throw new Error(); // This cannot happen
--- a/src/share/classes/java/util/jar/JarVerifier.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/util/jar/JarVerifier.java Fri May 02 20:39:34 2014 +0100 @@ -687,6 +687,8 @@ } else { matchUnsigned = true; } + } else { + matchUnsigned = true; } } @@ -789,23 +791,7 @@ // true if file is part of the signature mechanism itself static boolean isSigningRelated(String name) { - name = name.toUpperCase(Locale.ENGLISH); - if (!name.startsWith("META-INF/")) { - return false; - } - name = name.substring(9); - if (name.indexOf('/') != -1) { - return false; - } - if (name.endsWith(".DSA") - || name.endsWith(".RSA") - || name.endsWith(".SF") - || name.endsWith(".EC") - || name.startsWith("SIG-") - || name.equals("MANIFEST.MF")) { - return true; - } - return false; + return SignatureFileVerifier.isSigningRelated(name); } private Enumeration<String> unsignedEntryNames(JarFile jar) {
--- a/src/share/classes/java/util/logging/LogManager.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/util/logging/LogManager.java Fri May 02 20:39:34 2014 +0100 @@ -430,7 +430,7 @@ Logger result = getLogger(name); if (result == null) { // only allocate the new logger once - Logger newLogger = new Logger(name, resourceBundleName, caller); + Logger newLogger = new Logger(name, resourceBundleName, caller, false); do { if (addLogger(newLogger)) { // We successfully added the new Logger that we @@ -477,12 +477,12 @@ } while (logger == null); // LogManager will set the sysLogger's handlers via LogManager.addLogger method. - if (logger != sysLogger && sysLogger.getHandlers().length == 0) { + if (logger != sysLogger && sysLogger.accessCheckedHandlers().length == 0) { // if logger already exists but handlers not set final Logger l = logger; AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { - for (Handler hdl : l.getHandlers()) { + for (Handler hdl : l.accessCheckedHandlers()) { sysLogger.addHandler(hdl); } return null; @@ -766,7 +766,7 @@ Logger result = findLogger(name); if (result == null) { // only allocate the new system logger once - Logger newLogger = new Logger(name, resourceBundleName); + Logger newLogger = new Logger(name, resourceBundleName, null, true); do { if (addLocalLogger(newLogger)) { // We successfully added the new Logger that we @@ -1463,31 +1463,35 @@ // We use a subclass of Logger for the root logger, so // that we only instantiate the global handlers when they // are first needed. - private class RootLogger extends Logger { + private final class RootLogger extends Logger { private RootLogger() { - super("", null); + super("", null, null, true); setLevel(defaultLevel); } + @Override public void log(LogRecord record) { // Make sure that the global handlers have been instantiated. initializeGlobalHandlers(); super.log(record); } + @Override public void addHandler(Handler h) { initializeGlobalHandlers(); super.addHandler(h); } + @Override public void removeHandler(Handler h) { initializeGlobalHandlers(); super.removeHandler(h); } - public Handler[] getHandlers() { + @Override + Handler[] accessCheckedHandlers() { initializeGlobalHandlers(); - return super.getHandlers(); + return super.accessCheckedHandlers(); } }
--- a/src/share/classes/java/util/logging/Logger.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/java/util/logging/Logger.java Fri May 02 20:39:34 2014 +0100 @@ -189,7 +189,7 @@ // The fields relating to parent-child relationships and levels // are managed under a separate lock, the treeLock. - private static Object treeLock = new Object(); + private static final Object treeLock = new Object(); // We keep weak references from parents to children, but strong // references from children to parents. private volatile Logger parent; // our nearest parent. @@ -197,6 +197,7 @@ private volatile Level levelObject; private volatile int levelValue; // current effective level value private WeakReference<ClassLoader> callersClassLoaderRef; + private final boolean isSystemLogger; /** * GLOBAL_LOGGER_NAME is a name for the global logger. @@ -257,11 +258,12 @@ * no corresponding resource can be found. */ protected Logger(String name, String resourceBundleName) { - this(name, resourceBundleName, null); + this(name, resourceBundleName, null, false); } - Logger(String name, String resourceBundleName, Class<?> caller) { + Logger(String name, String resourceBundleName, Class<?> caller, boolean isSystemLogger) { this.manager = LogManager.getLogManager(); + this.isSystemLogger = isSystemLogger; setupResourceInfo(resourceBundleName, caller); this.name = name; levelValue = Level.INFO.intValue(); @@ -288,6 +290,7 @@ private Logger(String name) { // The manager field is not initialized here. this.name = name; + this.isSystemLogger = true; levelValue = Level.INFO.intValue(); } @@ -528,7 +531,7 @@ // cleanup some Loggers that have been GC'ed manager.drainLoggerRefQueueBounded(); Logger result = new Logger(null, resourceBundleName, - Reflection.getCallerClass()); + Reflection.getCallerClass(), false); result.anonymous = true; Logger root = manager.getLogger(""); result.doSetParent(root); @@ -606,15 +609,22 @@ Logger logger = this; while (logger != null) { - for (Handler handler : logger.getHandlers()) { + final Handler[] loggerHandlers = isSystemLogger + ? logger.accessCheckedHandlers() + : logger.getHandlers(); + for (Handler handler : loggerHandlers) { handler.publish(record); } - if (!logger.getUseParentHandlers()) { + final boolean useParentHdls = isSystemLogger + ? logger.useParentHandlers + : logger.getUseParentHandlers(); + + if (!useParentHdls) { break; } - logger = logger.getParent(); + logger = isSystemLogger ? logger.parent : logger.getParent(); } } @@ -1337,6 +1347,12 @@ * @return an array of all registered Handlers */ public Handler[] getHandlers() { + return accessCheckedHandlers(); + } + + // This method should ideally be marked final - but unfortunately + // it needs to be overridden by LogManager.RootLogger + Handler[] accessCheckedHandlers() { return handlers.toArray(emptyHandlers); } @@ -1672,11 +1688,13 @@ private String getEffectiveResourceBundleName() { Logger target = this; while (target != null) { - String rbn = target.getResourceBundleName(); + final String rbn = isSystemLogger + ? target.resourceBundleName + : target.getResourceBundleName(); if (rbn != null) { return rbn; } - target = target.getParent(); + target = isSystemLogger ? target.parent : target.getParent(); } return null; }
--- a/src/share/classes/javax/script/ScriptEngineManager.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/javax/script/ScriptEngineManager.java Fri May 02 20:39:34 2014 +0100 @@ -85,15 +85,18 @@ nameAssociations = new HashMap<String, ScriptEngineFactory>(); extensionAssociations = new HashMap<String, ScriptEngineFactory>(); mimeTypeAssociations = new HashMap<String, ScriptEngineFactory>(); - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - initEngines(loader); - return null; - } - }); + List<ScriptEngineFactory> facList = AccessController.doPrivileged( + new PrivilegedAction<List<ScriptEngineFactory>>() { + public List<ScriptEngineFactory> run() { + return initEngines(loader); + } + }); + for (ScriptEngineFactory fac : facList) { + engineSpis.add(fac); + } } - private void initEngines(final ClassLoader loader) { + private List<ScriptEngineFactory> initEngines(final ClassLoader loader) { Iterator itr = null; try { if (loader != null) { @@ -110,14 +113,15 @@ // do not throw any exception here. user may want to // manage his/her own factories using this manager // by explicit registratation (by registerXXX) methods. - return; + return null; } + final List<ScriptEngineFactory> facList = new ArrayList<>(); try { while (itr.hasNext()) { try { ScriptEngineFactory fact = (ScriptEngineFactory) itr.next(); - engineSpis.add(fact); + facList.add(fact); } catch (ServiceConfigurationError err) { System.err.println("ScriptEngineManager providers.next(): " + err.getMessage()); @@ -137,8 +141,8 @@ // do not throw any exception here. user may want to // manage his/her own factories using this manager // by explicit registratation (by registerXXX) methods. - return; } + return facList; } /**
--- a/src/share/classes/javax/security/auth/Subject.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/javax/security/auth/Subject.java Fri May 02 20:39:34 2014 +0100 @@ -941,14 +941,30 @@ /** * Reads this object from a stream (i.e., deserializes it) */ + @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { - s.defaultReadObject(); + ObjectInputStream.GetField gf = s.readFields(); + + readOnly = gf.get("readOnly", false); + + Set<Principal> inputPrincs = (Set<Principal>)gf.get("principals", null); // Rewrap the principals into a SecureSet - principals = Collections.synchronizedSet(new SecureSet<Principal> - (this, PRINCIPAL_SET, principals)); + if (inputPrincs == null) { + throw new NullPointerException + (ResourcesMgr.getString("invalid.null.input.s.")); + } + try { + principals = Collections.synchronizedSet(new SecureSet<Principal> + (this, PRINCIPAL_SET, inputPrincs)); + } catch (NullPointerException npe) { + // Sometimes people deserialize the principals set only. + // Subject is not accessible, so just don't fail. + principals = Collections.synchronizedSet + (new SecureSet<Principal>(this, PRINCIPAL_SET)); + } // The Credential <code>Set</code> is not serialized, but we do not // want the default deserialization routine to set it to null.
--- a/src/share/classes/javax/sql/rowset/RowSetProvider.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/javax/sql/rowset/RowSetProvider.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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 @@ -30,6 +30,7 @@ import java.sql.SQLException; import java.util.ServiceConfigurationError; import java.util.ServiceLoader; +import sun.reflect.misc.ReflectUtil; /** * A factory API that enables applications to obtain a @@ -127,15 +128,11 @@ factoryClassName = getSystemProperty(ROWSET_FACTORY_NAME); if (factoryClassName != null) { trace("Found system property, value=" + factoryClassName); - factory = (RowSetFactory) getFactoryClass(factoryClassName, null, true).newInstance(); + factory = (RowSetFactory) ReflectUtil.newInstance(getFactoryClass(factoryClassName, null, true)); } - } catch (ClassNotFoundException e) { - throw new SQLException( - "RowSetFactory: " + factoryClassName + " not found", e); - } catch (Exception e) { - throw new SQLException( - "RowSetFactory: " + factoryClassName + " could not be instantiated: " + e, - e); + } catch (Exception e) { + throw new SQLException( "RowSetFactory: " + factoryClassName + + " could not be instantiated: ", e); } // Check to see if we found the RowSetFactory via a System property @@ -180,6 +177,16 @@ throws SQLException { trace("***In newInstance()"); + + if(factoryClassName == null) { + throw new SQLException("Error: factoryClassName cannot be null"); + } + try { + ReflectUtil.checkPackageAccess(factoryClassName); + } catch (java.security.AccessControlException e) { + throw new SQLException("Access Exception",e); + } + try { Class providerClass = getFactoryClass(factoryClassName, cl, false); RowSetFactory instance = (RowSetFactory) providerClass.newInstance(); @@ -292,6 +299,7 @@ }); } catch (SecurityException se) { if (debug) { + trace("error getting " + propName + ": "+ se); se.printStackTrace(); } }
--- a/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2013, 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 @@ -30,6 +30,7 @@ import java.io.*; import java.math.*; import java.util.Map; +import sun.reflect.misc.ReflectUtil; /** * An input stream used for custom mapping user-defined types (UDTs). @@ -606,13 +607,9 @@ // create new instance of the class SQLData obj = null; try { - obj = (SQLData)c.newInstance(); - } catch (java.lang.InstantiationException ex) { - throw new SQLException("Unable to instantiate: " + - ex.getMessage()); - } catch (java.lang.IllegalAccessException ex) { - throw new SQLException("Unable to instantiate: " + - ex.getMessage()); + obj = (SQLData)ReflectUtil.newInstance(c); + } catch (Exception ex) { + throw new SQLException("Unable to Instantiate: ", ex); } // get the attributes from the struct Object attribs[] = s.getAttributes(map);
--- a/src/share/classes/javax/sql/rowset/spi/SyncFactory.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/javax/sql/rowset/spi/SyncFactory.java Fri May 02 20:39:34 2014 +0100 @@ -37,8 +37,11 @@ import java.io.FileNotFoundException; import java.security.AccessController; import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import javax.naming.*; +import sun.reflect.misc.ReflectUtil; /** * The Service Provider Interface (SPI) mechanism that generates <code>SyncProvider</code> @@ -343,7 +346,7 @@ // Local implementation class names and keys from Properties // file, translate names into Class objects using Class.forName // and store mappings - Properties properties = new Properties(); + final Properties properties = new Properties(); if (implementations == null) { implementations = new Hashtable(); @@ -372,6 +375,7 @@ } }); } catch (Exception ex) { + System.out.println("errorget rowset.properties: " + ex); strRowsetProperties = null; } if (strRowsetProperties != null) { @@ -391,16 +395,33 @@ strFileSep + "rowset" + strFileSep + "rowset.properties"; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); + final ClassLoader cl = Thread.currentThread().getContextClassLoader(); - try (InputStream stream = - (cl == null) ? ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES) - : cl.getResourceAsStream(ROWSET_PROPERTIES)) { - if (stream == null) { - throw new SyncFactoryException( - "Resource " + ROWSET_PROPERTIES + " not found"); + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() { + @Override + public Void run() throws SyncFactoryException, IOException, FileNotFoundException { + try (InputStream stream = (cl == null) ? + ClassLoader.getSystemResourceAsStream(ROWSET_PROPERTIES) + : cl.getResourceAsStream(ROWSET_PROPERTIES)) { + if (stream == null) { + throw new SyncFactoryException("Resource " + ROWSET_PROPERTIES + " not found"); + } + properties.load(stream); + } + return null; + } + + }); + } catch (PrivilegedActionException ex) { + Throwable e = ex.getException(); + if (e instanceof SyncFactoryException) { + throw (SyncFactoryException) e; + } else { + SyncFactoryException sfe = new SyncFactoryException(); + sfe.initCause(ex.getException()); + throw sfe; } - properties.load(stream); } parseProperties(properties); @@ -560,6 +581,13 @@ return new com.sun.rowset.providers.RIOptimisticProvider(); } + try { + ReflectUtil.checkPackageAccess(providerID); + } catch (java.security.AccessControlException e) { + SyncFactoryException sfe = new SyncFactoryException(); + sfe.initCause(e); + throw sfe; + } // Attempt to invoke classname from registered SyncProvider list Class c = null; try { @@ -568,7 +596,7 @@ /** * The SyncProvider implementation of the user will be in * the classpath. We need to find the ClassLoader which loads - * this SyncFactory and try to laod the SyncProvider class from + * this SyncFactory and try to load the SyncProvider class from * there. **/ c = Class.forName(providerID, true, cl);
--- a/src/share/classes/sun/awt/AWTAccessor.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/awt/AWTAccessor.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, 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 @@ -29,6 +29,7 @@ import java.awt.KeyboardFocusManager; import java.awt.DefaultKeyboardFocusManager; import java.awt.event.InputEvent; +import java.awt.event.InvocationEvent; import java.awt.event.KeyEvent; import java.awt.geom.Point2D; @@ -238,8 +239,8 @@ AccessControlContext getAccessControlContext(Component comp); /** - * Revalidates the component synchronously. - */ + * Revalidates the component synchronously. + */ void revalidateSynchronously(Component comp); } @@ -703,6 +704,25 @@ } /* + * An accessor object for the InvocationEvent class + */ + public interface InvocationEventAccessor { + /** + * Disposes the InvocationEvent + */ + void dispose(InvocationEvent event); + + /** + * Creates an InvocationEvent with a completion listener - + * a Runnable whose run() method will be called immediately after + * the event is dispatched or disposed + */ + InvocationEvent createEvent(Object source, Runnable runnable, Runnable listener, + boolean catchThrowables); + } + + + /* * Accessor instances are initialized in the static initializers of * corresponding AWT classes by using setters defined below. */ @@ -729,6 +749,7 @@ private static TrayIconAccessor trayIconAccessor; private static DefaultKeyboardFocusManagerAccessor defaultKeyboardFocusManagerAccessor; private static SequencedEventAccessor sequencedEventAccessor; + private static InvocationEventAccessor invocationEventAccessor; private static ToolkitAccessor toolkitAccessor; /* @@ -1142,4 +1163,18 @@ return toolkitAccessor; } + + /* + * Get the accessor object for the java.awt.event.InvocationEvent class. + */ + public static void setInvocationEventAccessor(InvocationEventAccessor invocationEventAccessor) { + AWTAccessor.invocationEventAccessor = invocationEventAccessor; + } + + /* + * Set the accessor object for the java.awt.event.InvocationEvent class. + */ + public static InvocationEventAccessor getInvocationEventAccessor() { + return invocationEventAccessor; + } }
--- a/src/share/classes/sun/awt/AWTAutoShutdown.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/awt/AWTAutoShutdown.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2014, 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 @@ -26,10 +26,13 @@ package sun.awt; import java.awt.AWTEvent; -import java.util.Collections; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.Map; + +import sun.misc.ThreadGroupUtils; import sun.util.logging.PlatformLogger; /** @@ -212,7 +215,13 @@ synchronized (activationLock) { synchronized (mainLock) { if (!isReadyToShutdown() && blockerThread == null) { - activateBlockerThread(); + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + activateBlockerThread(); + return null; + } + }); } else { mainLock.notifyAll(); timeoutPassed = false; @@ -326,9 +335,12 @@ /** * Creates and starts a new blocker thread. Doesn't return until * the new blocker thread starts. + * + * Must be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION} */ private void activateBlockerThread() { - Thread thread = new Thread(this, "AWT-Shutdown"); + Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), this, "AWT-Shutdown"); + thread.setContextClassLoader(null); thread.setDaemon(false); blockerThread = thread; thread.start();
--- a/src/share/classes/sun/awt/SunToolkit.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/awt/SunToolkit.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, 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 @@ -37,6 +37,7 @@ import java.awt.SystemTray; import java.awt.event.InputEvent; import java.net.URL; +import java.security.PrivilegedAction; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition;
--- a/src/share/classes/sun/awt/datatransfer/ClipboardTransferable.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/awt/datatransfer/ClipboardTransferable.java Fri May 02 20:39:34 2014 +0100 @@ -87,7 +87,7 @@ HashMap cached_data = new HashMap(formats.length, 1.0f); Map flavorsForFormats = DataTransferer.getInstance(). - getFlavorsForFormats(formats, SunClipboard.flavorMap); + getFlavorsForFormats(formats, SunClipboard.getDefaultFlavorTable()); for (Iterator iter = flavorsForFormats.keySet().iterator(); iter.hasNext(); ) {
--- a/src/share/classes/sun/awt/datatransfer/SunClipboard.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/awt/datatransfer/SunClipboard.java Fri May 02 20:39:34 2014 +0100 @@ -64,9 +64,6 @@ public abstract class SunClipboard extends Clipboard implements PropertyChangeListener { - public static final FlavorTable flavorMap = - (FlavorTable)SystemFlavorMap.getDefaultFlavorMap(); - private AppContext contentsContext = null; private final Object CLIPBOARD_FLAVOR_LISTENER_KEY; @@ -172,7 +169,7 @@ long[] formats = getClipboardFormatsOpenClose(); return DataTransferer.getInstance(). - getFlavorsForFormatsAsArray(formats, flavorMap); + getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable()); } /** @@ -218,7 +215,7 @@ long[] formats = getClipboardFormats(); Long lFormat = (Long)DataTransferer.getInstance(). - getFlavorsForFormats(formats, flavorMap).get(flavor); + getFlavorsForFormats(formats, getDefaultFlavorTable()).get(flavor); if (lFormat == null) { throw new UnsupportedFlavorException(flavor); @@ -349,7 +346,7 @@ private static Set formatArrayAsDataFlavorSet(long[] formats) { return (formats == null) ? null : DataTransferer.getInstance(). - getFlavorsForFormatsAsSet(formats, flavorMap); + getFlavorsForFormatsAsSet(formats, getDefaultFlavorTable()); } @@ -469,4 +466,7 @@ } } + public static FlavorTable getDefaultFlavorTable() { + return (FlavorTable) SystemFlavorMap.getDefaultFlavorMap(); + } }
--- a/src/share/classes/sun/font/CreatedFontTracker.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/font/CreatedFontTracker.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, 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 @@ -27,12 +27,15 @@ import java.io.File; import java.io.OutputStream; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import sun.awt.AppContext; +import sun.misc.ThreadGroupUtils; public class CreatedFontTracker { @@ -112,28 +115,25 @@ static void init() { if (t == null) { // Add a shutdown hook to remove the temp file. - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup tg = - Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; - tg = tgn, tgn = tg.getParent()); - t = new Thread(tg, new Runnable() { - public void run() { - runHooks(); - } - }); - t.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(t); - return null; - } - }); + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + t = new Thread(rootTG, new Runnable() { + @Override + public void run() { + runHooks(); + } + }); + t.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(t); + return null; + } + }); } }
--- a/src/share/classes/sun/font/SunFontManager.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/font/SunFontManager.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, 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 @@ -52,6 +52,7 @@ import sun.awt.AppContext; import sun.awt.FontConfiguration; import sun.awt.SunToolkit; +import sun.misc.ThreadGroupUtils; import sun.java2d.FontSupport; import sun.util.logging.PlatformLogger; @@ -2521,24 +2522,20 @@ }); } }; - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - /* The thread must be a member of a thread group - * which will not get GCed before VM exit. - * Make its parent the top-level thread group. - */ - ThreadGroup tg = - Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; - tg = tgn, tgn = tg.getParent()); - fileCloser = new Thread(tg, fileCloserRunnable); - fileCloser.setContextClassLoader(null); - Runtime.getRuntime().addShutdownHook(fileCloser); - return null; - } - }); + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + /* The thread must be a member of a thread group + * which will not get GCed before VM exit. + * Make its parent the top-level thread group. + */ + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + fileCloser = new Thread(rootTG, fileCloserRunnable); + fileCloser.setContextClassLoader(null); + Runtime.getRuntime().addShutdownHook(fileCloser); + return null; + } + }); } } }
--- a/src/share/classes/sun/java2d/Disposer.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/java2d/Disposer.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2014, 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 @@ -25,10 +25,14 @@ package sun.java2d; +import sun.misc.ThreadGroupUtils; + import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.PhantomReference; import java.lang.ref.WeakReference; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Hashtable; @@ -71,26 +75,22 @@ } } disposerInstance = new Disposer(); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { /* The thread must be a member of a thread group * which will not get GCed before VM exit. * Make its parent the top-level thread group. */ - ThreadGroup tg = Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; - tg = tgn, tgn = tg.getParent()); - Thread t = - new Thread(tg, disposerInstance, "Java2D Disposer"); - t.setContextClassLoader(null); - t.setDaemon(true); - t.setPriority(Thread.MAX_PRIORITY); - t.start(); - return null; + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + Thread t = new Thread(rootTG, disposerInstance, "Java2D Disposer"); + t.setContextClassLoader(null); + t.setDaemon(true); + t.setPriority(Thread.MAX_PRIORITY); + t.start(); + return null; + } } - } ); }
--- a/src/share/classes/sun/java2d/opengl/OGLRenderQueue.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/java2d/opengl/OGLRenderQueue.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2014, 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 @@ -25,6 +25,7 @@ package sun.java2d.opengl; +import sun.misc.ThreadGroupUtils; import sun.java2d.pipe.RenderBuffer; import sun.java2d.pipe.RenderQueue; import static sun.java2d.pipe.BufferedOpCodes.*; @@ -48,12 +49,9 @@ * which will not get GCed before VM exit. */ flusher = AccessController.doPrivileged(new PrivilegedAction<QueueFlusher>() { + @Override public QueueFlusher run() { - ThreadGroup rootThreadGroup = Thread.currentThread().getThreadGroup(); - while (rootThreadGroup.getParent() != null) { - rootThreadGroup = rootThreadGroup.getParent(); - } - return new QueueFlusher(rootThreadGroup); + return new QueueFlusher(ThreadGroupUtils.getRootThreadGroup()); } }); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/sun/misc/InnocuousThread.java Fri May 02 20:39:34 2014 +0100 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2013, 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 GNUNSAFE 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 WITHOUNSAFET + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICUNSAFELAR PUNSAFERPOSE. See the GNUNSAFE 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 GNUNSAFE 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 UNSAFESA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 UNSAFESA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.misc; + +import java.security.AccessControlContext; +import java.security.ProtectionDomain; + +/** + * A thread that has no permissions, is not a member of any user-defined + * ThreadGroup and supports the ability to erase ThreadLocals. + * + * @implNote Based on the implementation of InnocuousForkJoinWorkerThread. + */ +public final class InnocuousThread extends Thread { + private static final Unsafe UNSAFE; + private static final ThreadGroup THREADGROUP; + private static final AccessControlContext ACC; + private static final long THREADLOCALS; + private static final long INHERITABLETHREADLOCALS; + private static final long INHERITEDACCESSCONTROLCONTEXT; + + public InnocuousThread(Runnable target) { + super(THREADGROUP, target, "anInnocuousThread"); + UNSAFE.putOrderedObject(this, INHERITEDACCESSCONTROLCONTEXT, ACC); + eraseThreadLocals(); + } + + @Override + public ClassLoader getContextClassLoader() { + // always report system class loader + return ClassLoader.getSystemClassLoader(); + } + + @Override + public void setUncaughtExceptionHandler(UncaughtExceptionHandler x) { + // silently fail + } + + @Override + public void setContextClassLoader(ClassLoader cl) { + throw new SecurityException("setContextClassLoader"); + } + + // ensure run method is run only once + private volatile boolean hasRun; + + @Override + public void run() { + if (Thread.currentThread() == this && !hasRun) { + hasRun = true; + super.run(); + } + } + + /** + * Drops all thread locals (and inherited thread locals). + */ + public void eraseThreadLocals() { + UNSAFE.putObject(this, THREADLOCALS, null); + UNSAFE.putObject(this, INHERITABLETHREADLOCALS, null); + } + + // Use Unsafe to access Thread group and ThreadGroup parent fields + static { + try { + ACC = new AccessControlContext(new ProtectionDomain[] { + new ProtectionDomain(null, null) + }); + + // Find and use topmost ThreadGroup as parent of new group + UNSAFE = Unsafe.getUnsafe(); + Class<?> tk = Thread.class; + Class<?> gk = ThreadGroup.class; + + THREADLOCALS = UNSAFE.objectFieldOffset + (tk.getDeclaredField("threadLocals")); + INHERITABLETHREADLOCALS = UNSAFE.objectFieldOffset + (tk.getDeclaredField("inheritableThreadLocals")); + INHERITEDACCESSCONTROLCONTEXT = UNSAFE.objectFieldOffset + (tk.getDeclaredField("inheritedAccessControlContext")); + + long tg = UNSAFE.objectFieldOffset(tk.getDeclaredField("group")); + long gp = UNSAFE.objectFieldOffset(gk.getDeclaredField("parent")); + ThreadGroup group = (ThreadGroup) + UNSAFE.getObject(Thread.currentThread(), tg); + + while (group != null) { + ThreadGroup parent = (ThreadGroup)UNSAFE.getObject(group, gp); + if (parent == null) + break; + group = parent; + } + THREADGROUP = new ThreadGroup(group, "InnocuousThreadGroup"); + } catch (Exception e) { + throw new Error(e); + } + } +}
--- a/src/share/classes/sun/misc/Service.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/misc/Service.java Fri May 02 20:39:34 2014 +0100 @@ -299,7 +299,7 @@ return service.cast(c.newInstance()); } catch (Throwable x) { fail(service, - "Provider " + cn + " could not be instantiated: " + x, + "Provider " + cn + " could not be instantiated", x); } return null; /* This cannot happen */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/sun/misc/ThreadGroupUtils.java Fri May 02 20:39:34 2014 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014, 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 sun.misc; + +/** + * A utility class needed to access the root {@code ThreadGroup} + * + * The class should not depend on any others, because it' called from JNI_OnLoad of the AWT + * native library. Triggering class loading could could lead to a deadlock. + */ +public final class ThreadGroupUtils { + + private ThreadGroupUtils() { + // Avoid instantiation + } + + /** + * Returns a root thread group. + * Should be called with {@link sun.security.util.SecurityConstants#MODIFY_THREADGROUP_PERMISSION} + * + * @return a root {@code ThreadGroup} + */ + public static ThreadGroup getRootThreadGroup() { + ThreadGroup currentTG = Thread.currentThread().getThreadGroup(); + ThreadGroup parentTG = currentTG.getParent(); + while (parentTG != null) { + currentTG = parentTG; + parentTG = currentTG.getParent(); + } + return currentTG; + } +}
--- a/src/share/classes/sun/nio/ch/Invoker.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/nio/ch/Invoker.java Fri May 02 20:39:34 2014 +0100 @@ -130,6 +130,18 @@ // clear interrupt Thread.interrupted(); + + // clear thread locals when in default thread pool + if (System.getSecurityManager() != null) { + Thread me = Thread.currentThread(); + if (me instanceof sun.misc.InnocuousThread) { + GroupAndInvokeCount thisGroupAndInvokeCount = myGroupAndInvokeCount.get(); + ((sun.misc.InnocuousThread)me).eraseThreadLocals(); + if (thisGroupAndInvokeCount != null) { + myGroupAndInvokeCount.set(thisGroupAndInvokeCount); + } + } + } } /**
--- a/src/share/classes/sun/nio/ch/ThreadPool.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/nio/ch/ThreadPool.java Fri May 02 20:39:34 2014 +0100 @@ -27,6 +27,7 @@ import java.util.concurrent.*; import java.security.AccessController; +import java.security.PrivilegedAction; import sun.security.action.GetPropertyAction; import sun.security.action.GetIntegerAction; @@ -39,14 +40,6 @@ "java.nio.channels.DefaultThreadPool.threadFactory"; private static final String DEFAULT_THREAD_POOL_INITIAL_SIZE = "java.nio.channels.DefaultThreadPool.initialSize"; - private static final ThreadFactory defaultThreadFactory = new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r); - t.setDaemon(true); - return t; - } - }; private final ExecutorService executor; @@ -79,7 +72,29 @@ } static ThreadFactory defaultThreadFactory() { - return defaultThreadFactory; + if (System.getSecurityManager() == null) { + return new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + } + }; + } else { + return new ThreadFactory() { + @Override + public Thread newThread(final Runnable r) { + return (Thread) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + Thread t = new sun.misc.InnocuousThread(r); + t.setDaemon(true); + return t; + } + }); + } + }; + } } private static class DefaultThreadPoolHolder { @@ -100,7 +115,7 @@ // default to thread factory that creates daemon threads ThreadFactory threadFactory = getDefaultThreadPoolThreadFactory(); if (threadFactory == null) - threadFactory = defaultThreadFactory; + threadFactory = defaultThreadFactory(); // create thread pool ExecutorService executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
--- a/src/share/classes/sun/security/provider/SeedGenerator.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/security/provider/SeedGenerator.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, 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 @@ -173,8 +173,8 @@ md.update(p.getProperty(s).getBytes()); } - md.update - (InetAddress.getLocalHost().toString().getBytes()); + // Include network adapter names (and a Mac address) + addNetworkAdapterInfo(md); // The temporary dir File f = new File(p.getProperty("java.io.tmpdir")); @@ -212,6 +212,31 @@ return md.digest(); } + /* + * Include network adapter names and, if available, a Mac address + * + * See also java.util.concurrent.ThreadLocalRandom.initialSeed() + */ + private static void addNetworkAdapterInfo(MessageDigest md) { + + try { + Enumeration<NetworkInterface> ifcs = + NetworkInterface.getNetworkInterfaces(); + while (ifcs.hasMoreElements()) { + NetworkInterface ifc = ifcs.nextElement(); + md.update(ifc.toString().getBytes()); + if (!ifc.isVirtual()) { // skip fake addresses + byte[] bs = ifc.getHardwareAddress(); + if (bs != null) { + md.update(bs); + break; + } + } + } + } catch (Exception ignore) { + } + } + /** * Helper function to convert a long into a byte array (least significant * byte first).
--- a/src/share/classes/sun/security/provider/certpath/AlgorithmChecker.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/security/provider/certpath/AlgorithmChecker.java Fri May 02 20:39:34 2014 +0100 @@ -75,7 +75,7 @@ private PublicKey prevPubKey; private final static Set<CryptoPrimitive> SIGNATURE_PRIMITIVE_SET = - EnumSet.of(CryptoPrimitive.SIGNATURE); + Collections.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE)); private final static DisabledAlgorithmConstraints certPathDefaultConstraints = new DisabledAlgorithmConstraints(
--- a/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/security/provider/certpath/ldap/LDAPCertStore.java Fri May 02 20:39:34 2014 +0100 @@ -50,6 +50,7 @@ import sun.security.util.Cache; import sun.security.util.Debug; import sun.security.x509.X500Name; +import sun.security.action.GetBooleanAction; import sun.security.action.GetPropertyAction; /** @@ -135,6 +136,14 @@ private final static String PROP_LIFETIME = "sun.security.certpath.ldap.cache.lifetime"; + /* + * Internal system property, that when set to "true", disables the + * JNDI application resource files lookup to prevent recursion issues + * when validating signed JARs with LDAP URLs in certificates. + */ + private final static String PROP_DISABLE_APP_RESOURCE_FILES = + "sun.security.certpath.ldap.disable.app.resource.files"; + static { String s = AccessController.doPrivileged( new GetPropertyAction(PROP_LIFETIME)); @@ -236,6 +245,17 @@ env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); + + // If property is set to true, disable application resource file lookup. + boolean disableAppResourceFiles = AccessController.doPrivileged( + new GetBooleanAction(PROP_DISABLE_APP_RESOURCE_FILES)); + if (disableAppResourceFiles) { + if (debug != null) { + debug.println("LDAPCertStore disabling app resource files"); + } + env.put("com.sun.naming.disable.app.resource.files", "true"); + } + try { ctx = new InitialDirContext(env); /*
--- a/src/share/classes/sun/security/rsa/RSAPadding.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/security/rsa/RSAPadding.java Fri May 02 20:39:34 2014 +0100 @@ -25,11 +25,9 @@ package sun.security.rsa; -import java.math.BigInteger; import java.util.*; import java.security.*; -import java.security.interfaces.*; import java.security.spec.*; import javax.crypto.BadPaddingException; @@ -41,21 +39,41 @@ /** * RSA padding and unpadding. * - * Format of PKCS#1 v1.5 padding is: + * The various PKCS#1 versions can be found in the EMC/RSA Labs + * web site, which is currently: + * + * http://www.emc.com/emc-plus/rsa-labs/index.htm + * + * or in the IETF RFCs derived from the above PKCS#1 standards. + * + * RFC 2313: v1.5 + * RFC 2437: v2.0 + * RFC 3447: v2.1 + * + * The format of PKCS#1 v1.5 padding is: + * * 0x00 | BT | PS...PS | 0x00 | data...data + * * where BT is the blocktype (1 or 2). The length of the entire string * must be the same as the size of the modulus (i.e. 128 byte for a 1024 bit * key). Per spec, the padding string must be at least 8 bytes long. That * leaves up to (length of key in bytes) - 11 bytes for the data. * - * OAEP padding is a bit more complicated and has a number of options. - * We support: + * OAEP padding was introduced in PKCS#1 v2.0 and is a bit more complicated + * and has a number of options. We support: + * * . arbitrary hash functions ('Hash' in the specification), MessageDigest * implementation must be available * . MGF1 as the mask generation function * . the empty string as the default value for label L and whatever * specified in javax.crypto.spec.OAEPParameterSpec * + * The algorithms (representations) are forwards-compatible: that is, + * the algorithm described in previous releases are in later releases. + * However, additional comments/checks/clarifications were added to the + * later versions based on real-world experience (e.g. stricter v1.5 + * format checking.) + * * Note: RSA keys should be at least 512 bits long * * @since 1.5 @@ -156,7 +174,8 @@ throw new InvalidAlgorithmParameterException ("Unsupported MGF algo: " + mgfName); } - mgfMdName = ((MGF1ParameterSpec)spec.getMGFParameters()).getDigestAlgorithm(); + mgfMdName = ((MGF1ParameterSpec)spec.getMGFParameters()) + .getDigestAlgorithm(); PSource pSrc = spec.getPSource(); String pSrcAlgo = pSrc.getAlgorithm(); if (!pSrcAlgo.equalsIgnoreCase("PSpecified")) { @@ -198,7 +217,7 @@ */ private static byte[] getInitialHash(MessageDigest md, byte[] digestInput) { - byte[] result = null; + byte[] result; if ((digestInput == null) || (digestInput.length == 0)) { String digestName = md.getAlgorithm(); result = emptyHashes.get(digestName); @@ -213,8 +232,8 @@ } /** - * Return the maximum size of the plaintext data that can be processed using - * this object. + * Return the maximum size of the plaintext data that can be processed + * using this object. */ public int getMaxDataSize() { return maxDataSize; @@ -262,7 +281,7 @@ */ public byte[] unpad(byte[] padded) throws BadPaddingException { if (padded.length != paddedSize) { - throw new BadPaddingException("Padded length must be " + paddedSize); + throw new BadPaddingException("Decryption error"); } switch (type) { case PAD_NONE: @@ -282,7 +301,8 @@ */ private byte[] padV15(byte[] data) throws BadPaddingException { byte[] padded = new byte[paddedSize]; - System.arraycopy(data, 0, padded, paddedSize - data.length, data.length); + System.arraycopy(data, 0, padded, paddedSize - data.length, + data.length); int psSize = paddedSize - 3 - data.length; int k = 0; padded[k++] = 0; @@ -317,55 +337,53 @@ } /** - * PKCS#1 v1.5 unpadding (blocktype 1 and 2). + * PKCS#1 v1.5 unpadding (blocktype 1 (signature) and 2 (encryption)). * * Note that we want to make it a constant-time operation */ private byte[] unpadV15(byte[] padded) throws BadPaddingException { int k = 0; - BadPaddingException bpe = null; + boolean bp = false; if (padded[k++] != 0) { - bpe = new BadPaddingException("Data must start with zero"); + bp = true; } - if (padded[k++] != type && bpe == null) { - bpe = new BadPaddingException("Blocktype mismatch: " + padded[1]); + if (padded[k++] != type) { + bp = true; } int p = 0; while (k < padded.length) { int b = padded[k++] & 0xff; - if (b == 0 && p == 0) { + if ((b == 0) && (p == 0)) { p = k; } - if (k == padded.length && p == 0 && bpe == null) { - bpe = new BadPaddingException("Padding string not terminated"); + if ((k == padded.length) && (p == 0)) { + bp = true; } if ((type == PAD_BLOCKTYPE_1) && (b != 0xff) && - p == 0 && bpe == null) { - bpe = new BadPaddingException("Padding byte not 0xff: " + b); + (p == 0)) { + bp = true; } } int n = padded.length - p; - if (n > maxDataSize && bpe == null) { - bpe = new BadPaddingException("Padding string too short"); + if (n > maxDataSize) { + bp = true; } // copy useless padding array for a constant-time method - // - // Is it necessary? byte[] padding = new byte[p]; System.arraycopy(padded, 0, padding, 0, p); byte[] data = new byte[n]; System.arraycopy(padded, p, data, 0, n); - if (bpe == null) { - bpe = new BadPaddingException("Unused exception"); - } else { + BadPaddingException bpe = new BadPaddingException("Decryption error"); + + if (bp) { throw bpe; + } else { + return data; } - - return data; } /** @@ -424,10 +442,11 @@ */ private byte[] unpadOAEP(byte[] padded) throws BadPaddingException { byte[] EM = padded; + boolean bp = false; int hLen = lHash.length; if (EM[0] != 0) { - throw new BadPaddingException("Data must start with zero"); + bp = true; } int seedStart = 1; @@ -442,29 +461,48 @@ // verify lHash == lHash' for (int i = 0; i < hLen; i++) { if (lHash[i] != EM[dbStart + i]) { - throw new BadPaddingException("lHash mismatch"); + bp = true; + } + } + + int padStart = dbStart + hLen; + int onePos = -1; + + for (int i = padStart; i < EM.length; i++) { + int value = EM[i]; + if (onePos == -1) { + if (value == 0x00) { + // continue; + } else if (value == 0x01) { + onePos = i; + } else { // Anything other than {0,1} is bad. + bp = true; + } } } - // skip over padding (0x00 bytes) - int i = dbStart + hLen; - while (EM[i] == 0) { - i++; - if (i >= EM.length) { - throw new BadPaddingException("Padding string not terminated"); - } + // We either ran off the rails or found something other than 0/1. + if (onePos == -1) { + bp = true; + onePos = EM.length - 1; // Don't inadvertently return any data. } - if (EM[i++] != 1) { - throw new BadPaddingException - ("Padding string not terminated by 0x01 byte"); - } + int mStart = onePos + 1; + + // copy useless padding array for a constant-time method + byte [] tmp = new byte[mStart - padStart]; + System.arraycopy(EM, padStart, tmp, 0, tmp.length); - int mLen = EM.length - i; - byte[] m = new byte[mLen]; - System.arraycopy(EM, i, m, 0, mLen); + byte [] m = new byte[EM.length - mStart]; + System.arraycopy(EM, mStart, m, 0, m.length); + + BadPaddingException bpe = new BadPaddingException("Decryption error"); - return m; + if (bp) { + throw bpe; + } else { + return m; + } } /** @@ -478,7 +516,7 @@ private void mgf1(byte[] seed, int seedOfs, int seedLen, byte[] out, int outOfs, int maskLen) throws BadPaddingException { byte[] C = new byte[4]; // 32 bit counter - byte[] digest = new byte[20]; // 20 bytes is length of SHA-1 digest + byte[] digest = new byte[mgfMd.getDigestLength()]; while (maskLen > 0) { mgfMd.update(seed, seedOfs, seedLen); mgfMd.update(C); @@ -499,5 +537,4 @@ } } } - }
--- a/src/share/classes/sun/security/ssl/SignatureAndHashAlgorithm.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/security/ssl/SignatureAndHashAlgorithm.java Fri May 02 20:39:34 2014 +0100 @@ -68,7 +68,7 @@ // performance optimization private final static Set<CryptoPrimitive> SIGNATURE_PRIMITIVE_SET = - EnumSet.of(CryptoPrimitive.SIGNATURE); + Collections.unmodifiableSet(EnumSet.of(CryptoPrimitive.SIGNATURE)); // supported pairs of signature and hash algorithm private final static Map<Integer, SignatureAndHashAlgorithm> supportedMap;
--- a/src/share/classes/sun/security/tools/JarSigner.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/security/tools/JarSigner.java Fri May 02 20:39:34 2014 +0100 @@ -88,9 +88,6 @@ private static final String META_INF = "META-INF/"; - // prefix for new signature-related files in META-INF directory - private static final String SIG_PREFIX = META_INF + "SIG-"; - private static final Class[] PARAM_STRING = { String.class }; private static final String NONE = "NONE"; @@ -1516,22 +1513,7 @@ * . META-INF/*.EC */ private boolean signatureRelated(String name) { - String ucName = name.toUpperCase(Locale.ENGLISH); - if (ucName.equals(JarFile.MANIFEST_NAME) || - ucName.equals(META_INF) || - (ucName.startsWith(SIG_PREFIX) && - ucName.indexOf("/") == ucName.lastIndexOf("/"))) { - return true; - } - - if (ucName.startsWith(META_INF) && - SignatureFileVerifier.isBlockOrSF(ucName)) { - // .SF/.DSA/.RSA/.EC files in META-INF subdirs - // are not considered signature-related - return (ucName.indexOf("/") == ucName.lastIndexOf("/")); - } - - return false; + return SignatureFileVerifier.isSigningRelated(name); } Map<CodeSigner,String> cacheForSignerInfo = new IdentityHashMap<>();
--- a/src/share/classes/sun/security/util/SignatureFileVerifier.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/classes/sun/security/util/SignatureFileVerifier.java Fri May 02 20:39:34 2014 +0100 @@ -153,6 +153,52 @@ return false; } + /** + * Yet another utility method used by JarVerifier and JarSigner + * to determine what files are signature related, which includes + * the MANIFEST, SF files, known signature block files, and other + * unknown signature related files (those starting with SIG- with + * an optional [A-Z0-9]{1,3} extension right inside META-INF). + * + * @param s file name + * @return true if the input file name is signature related + */ + public static boolean isSigningRelated(String name) { + name = name.toUpperCase(Locale.ENGLISH); + if (!name.startsWith("META-INF/")) { + return false; + } + name = name.substring(9); + if (name.indexOf('/') != -1) { + return false; + } + if (isBlockOrSF(name) || name.equals("MANIFEST.MF")) { + return true; + } else if (name.startsWith("SIG-")) { + // check filename extension + // see http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Digital_Signatures + // for what filename extensions are legal + int extIndex = name.lastIndexOf('.'); + if (extIndex != -1) { + String ext = name.substring(extIndex + 1); + // validate length first + if (ext.length() > 3 || ext.length() < 1) { + return false; + } + // then check chars, must be in [a-zA-Z0-9] per the jar spec + for (int index = 0; index < ext.length(); index++) { + char cc = ext.charAt(index); + // chars are promoted to uppercase so skip lowercase checks + if ((cc < 'A' || cc > 'Z') && (cc < '0' || cc > '9')) { + return false; + } + } + } + return true; // no extension is OK + } + return false; + } + /** get digest from cache */ private MessageDigest getDigest(String algorithm)
--- a/src/share/native/com/sun/java/util/jar/pack/unpack.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/com/sun/java/util/jar/pack/unpack.cpp Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2014, 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 @@ -4779,39 +4779,7 @@ } else if (log_file[0] != '\0' && (errstrm = fopen(log_file,"a+")) != NULL) { return; } else { - char log_file_name[PATH_MAX+100]; - char tmpdir[PATH_MAX]; -#ifdef WIN32 - int n = GetTempPath(PATH_MAX,tmpdir); //API returns with trailing '\' - if (n < 1 || n > PATH_MAX) { - sprintf(tmpdir,"C:\\"); - } - sprintf(log_file_name, "%sunpack.log", tmpdir); -#else - sprintf(tmpdir,"/tmp"); - sprintf(log_file_name, "/tmp/unpack.log"); -#endif - if ((errstrm = fopen(log_file_name, "a+")) != NULL) { - log_file = errstrm_name = saveStr(log_file_name); - return ; - } - - char *tname = tempnam(tmpdir,"#upkg"); - if (tname == NULL) return; - sprintf(log_file_name, "%s", tname); - ::free(tname); - if ((errstrm = fopen(log_file_name, "a+")) != NULL) { - log_file = errstrm_name = saveStr(log_file_name); - return ; - } -#ifndef WIN32 - sprintf(log_file_name, "/dev/null"); - // On windows most likely it will fail. - if ( (errstrm = fopen(log_file_name, "a+")) != NULL) { - log_file = errstrm_name = saveStr(log_file_name); - return ; - } -#endif + fprintf(stderr, "Can not open log file %s\n", log_file); // Last resort // (Do not use stdout, since it might be jarout->jarfp.) errstrm = stderr;
--- a/src/share/native/sun/awt/giflib/dgif_lib.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/giflib/dgif_lib.c Fri May 02 20:39:34 2014 +0100 @@ -435,9 +435,7 @@ Private->PixelCount = (long)GifFile->Image.Width * (long)GifFile->Image.Height; - DGifSetupDecompress(GifFile); /* Reset decompress algorithm parameters. */ - - return GIF_OK; + return DGifSetupDecompress(GifFile); /* Reset decompress algorithm parameters. */ } /******************************************************************************
--- a/src/share/native/sun/awt/image/gif/gifdecoder.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/image/gif/gifdecoder.c Fri May 02 20:39:34 2014 +0100 @@ -249,6 +249,7 @@ /* fill the block */ len = (*env)->CallIntMethod(env, this, readID, blockh, remain, blockLength + 1); + if (len > blockLength + 1) len = blockLength + 1; if ((*env)->ExceptionOccurred(env)) { return 0; }
--- a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c Fri May 02 20:39:34 2014 +0100 @@ -939,6 +939,9 @@ JPEGImageReader_readInputDataID, sb->hstreamBuffer, 0, sb->bufferLength); + if ((ret > 0) && ((unsigned int)ret > sb->bufferLength)) { + ret = sb->bufferLength; + } if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); @@ -1035,6 +1038,7 @@ JPEGImageReader_readInputDataID, sb->hstreamBuffer, offset, buflen); + if ((ret > 0) && ((unsigned int)ret > buflen)) ret = buflen; if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo);
--- a/src/share/native/sun/awt/image/jpeg/jpeg-6b/jdmarker.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/image/jpeg/jpeg-6b/jdmarker.c Fri May 02 20:39:34 2014 +0100 @@ -349,6 +349,12 @@ TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, compptr->dc_tbl_no, compptr->ac_tbl_no); + + /* This CSi (cc) should differ from the previous CSi */ + for (ci = 0; ci < i; ci++) { + if (cinfo->cur_comp_info[ci] == compptr) + ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); + } } /* Collect the additional scan parameters Ss, Se, Ah/Al. */
--- a/src/share/native/sun/awt/image/jpeg/jpegdecoder.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/image/jpeg/jpegdecoder.c Fri May 02 20:39:34 2014 +0100 @@ -289,6 +289,7 @@ buflen = (*env)->GetArrayLength(env, src->hInputBuffer); ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID, src->hInputBuffer, 0, buflen); + if (ret > buflen) ret = buflen; if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } @@ -349,6 +350,7 @@ } ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID, src->hInputBuffer, offset, buflen); + if ((ret > 0) && ((unsigned int)ret > buflen)) ret = buflen; if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } @@ -424,6 +426,7 @@ ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID, src->hInputBuffer, 0, buflen); + if (ret > buflen) ret = buflen; if ((*env)->ExceptionOccurred(env)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); }
--- a/src/share/native/sun/awt/libpng/pngrtran.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/libpng/pngrtran.c Fri May 02 20:39:34 2014 +0100 @@ -1862,6 +1862,9 @@ info_ptr->bit_depth = 8; info_ptr->num_trans = 0; + + if (png_ptr->palette == NULL) + png_error (png_ptr, "Palette is NULL in indexed image"); } else {
--- a/src/share/native/sun/awt/libpng/pngset.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/libpng/pngset.c Fri May 02 20:39:34 2014 +0100 @@ -512,6 +512,17 @@ } } + if ((num_palette > 0 && palette == NULL) || + (num_palette == 0 +# ifdef PNG_MNG_FEATURES_SUPPORTED + && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 +# endif + )) + { + png_error(png_ptr, "Invalid palette"); + return; + } + /* It may not actually be necessary to set png_ptr->palette here; * we do it for backward compatibility with the way the png_handle_tRNS * function used to do the allocation.
--- a/src/share/native/sun/awt/medialib/awt_ImagingLib.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/awt/medialib/awt_ImagingLib.c Fri May 02 20:39:34 2014 +0100 @@ -228,6 +228,49 @@ } } +/* + * We have to make sure that awt_setPixels can be safely applied to the given pair of + * raster and mlib image. + * + * In particular, make sure that + * - dimension is the same + * - number of channels in mlib image corresponds to the number of bands in the raster + * - sample size in image and raster are the same. + * + * Returns: + * -1 to indicate failure, + * 1 to indicate success + */ +static int setPixelsFormMlibImage(JNIEnv *env, RasterS_t *rasterP, mlib_image* img) { + if (rasterP->width != img->width || rasterP->height != img->height) { + /* dimension does not match */ + return -1; + } + + if (rasterP->numBands != img->channels) { + /* number of bands does not match */ + return -1; + } + + switch (rasterP->dataType) { + case BYTE_DATA_TYPE: + if (img->type != MLIB_BYTE) { + return -1; + } + break; + case SHORT_DATA_TYPE: + if (img->type != MLIB_SHORT && img->type != MLIB_USHORT) { + return -1; + } + break; + default: + /* awt_setPixels does not support such rasters */ + return -1; + } + + return awt_setPixels(env, rasterP, mlib_ImageGetData(img)); +} + /*************************************************************************** * External Functions * ***************************************************************************/ @@ -700,7 +743,9 @@ /* Means that we couldn't write directly into the destination buffer */ if (ddata == NULL) { - retStatus = awt_setPixels(env, dstRasterP, mlib_ImageGetData(dst)); + if (storeRasterArray(env, srcRasterP, dstRasterP, dst) < 0) { + retStatus = setPixelsFormMlibImage(env, dstRasterP, dst); + } } /* Release the pinned memory */ @@ -1106,7 +1151,7 @@ if (ddata == NULL) { /* Need to store it back into the array */ if (storeRasterArray(env, srcRasterP, dstRasterP, dst) < 0) { - retStatus = awt_setPixels(env, dstRasterP, mlib_ImageGetData(dst)); + retStatus = setPixelsFormMlibImage(env, dstRasterP, dst); } } @@ -1432,6 +1477,14 @@ retStatus = 0; } + /* Release the LUT */ + for (i=0; i < lut_nbands; i++) { + (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, + (jbyte *) jtable[i].table, JNI_ABORT); + } + free ((void *) jtable); + free ((void *) tbl); + /* * Means that we couldn't write directly into * the destination buffer @@ -1445,13 +1498,6 @@ } } - /* Release the LUT */ - for (i=0; i < lut_nbands; i++) { - (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, - (jbyte *) jtable[i].table, JNI_ABORT); - } - free ((void *) jtable); - free ((void *) tbl); /* Release the pinned memory */ freeArray(env, srcImageP, src, sdata, dstImageP, dst, ddata); @@ -1669,18 +1715,20 @@ retStatus = 0; } + /* Release the LUT */ + for (i=0; i < lut_nbands; i++) { + (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, + (jbyte *) jtable[i].table, JNI_ABORT); + } + /* * Means that we couldn't write directly into * the destination buffer */ if (ddata == NULL) { - retStatus = awt_setPixels(env, dstRasterP, mlib_ImageGetData(dst)); - } - - /* Release the LUT */ - for (i=0; i < lut_nbands; i++) { - (*env)->ReleasePrimitiveArrayCritical(env, jtable[i].jArray, - (jbyte *) jtable[i].table, JNI_ABORT); + if (storeRasterArray(env, srcRasterP, dstRasterP, dst) < 0) { + retStatus = setPixelsFormMlibImage(env, dstRasterP, dst); + } } /* Release the pinned memory */ @@ -2640,7 +2688,7 @@ } } else if (mlibImP->type == MLIB_SHORT) { - return awt_setPixels(env, rasterP, mlibImP->data); + return setPixelsFormMlibImage(env, rasterP, mlibImP); } } else {
--- a/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/ContextualGlyphSubstProc2.cpp Fri May 02 20:39:34 2014 +0100 @@ -154,6 +154,7 @@ TTGlyphID glyphCode = (TTGlyphID) LE_GET_GLYPH(gid); if ((glyphCode >= firstGlyph) && (glyphCode < lastGlyph)) { LEReferenceToArrayOf<LookupValue> valueArray(lookupTable8, success, &lookupTable8->valueArray[0], glyphCount); + if (LE_FAILURE(success)) { return newGlyph; } newGlyph = SWAPW(valueArray(glyphCode - firstGlyph, success)); } }
--- a/src/share/native/sun/font/layout/ContextualSubstSubtables.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/ContextualSubstSubtables.cpp Fri May 02 20:39:34 2014 +0100 @@ -110,6 +110,8 @@ LEErrorCode &success, le_bool backtrack) { + if (LE_FAILURE(success)) { return FALSE; } + le_int32 direction = 1; le_int32 match = 0; @@ -255,6 +257,7 @@ le_uint16 matchCount = SWAPW(subRuleTable->glyphCount) - 1; le_uint16 substCount = SWAPW(subRuleTable->substCount); LEReferenceToArrayOf<TTGlyphID> inputGlyphArray(base, success, subRuleTable->inputGlyphArray, matchCount+2); + if (LE_FAILURE(success)) { return 0; } if (matchGlyphIDs(inputGlyphArray, matchCount, glyphIterator)) { LEReferenceToArrayOf<SubstitutionLookupRecord> substLookupRecordArray(base, success, (const SubstitutionLookupRecord *) &subRuleTable->inputGlyphArray[matchCount], substCount); @@ -315,6 +318,7 @@ LEReferenceToArrayOf<le_uint16> classArray(base, success, subClassRuleTable->classArray, matchCount+1); + if (LE_FAILURE(success)) { return 0; } if (matchGlyphClasses(classArray, matchCount, glyphIterator, classDefinitionTable, success)) { LEReferenceToArrayOf<SubstitutionLookupRecord> substLookupRecordArray(base, success, (const SubstitutionLookupRecord *) &subClassRuleTable->classArray[matchCount], substCount); @@ -573,7 +577,7 @@ if (matchGlyphClasses(inputClassArray, inputGlyphCount, glyphIterator, inputClassDefinitionTable, success)) { LEReferenceToArrayOf<SubstitutionLookupRecord> substLookupRecordArray(base, success, (const SubstitutionLookupRecord *) lookaheadClassArray.getAlias(lookaheadGlyphCount + 1, success), substCount); - + if (LE_FAILURE(success)) { return 0; } applySubstitutionLookups(lookupProcessor, substLookupRecordArray, substCount, glyphIterator, fontInstance, position, success); return inputGlyphCount + 1; @@ -601,6 +605,7 @@ le_uint16 backtrkGlyphCount = SWAPW(backtrackGlyphCount); le_uint16 inputGlyphCount = (le_uint16) SWAPW(backtrackCoverageTableOffsetArray[backtrkGlyphCount]); LEReferenceToArrayOf<Offset> inputCoverageTableOffsetArray(base, success, &backtrackCoverageTableOffsetArray[backtrkGlyphCount + 1], inputGlyphCount+2); // offset + if (LE_FAILURE(success)) { return 0; } const le_uint16 lookaheadGlyphCount = (le_uint16) SWAPW(inputCoverageTableOffsetArray[inputGlyphCount]); if( LE_FAILURE(success) ) { return 0; }
--- a/src/share/native/sun/font/layout/LigatureSubstProc2.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/LigatureSubstProc2.cpp Fri May 02 20:39:34 2014 +0100 @@ -95,7 +95,7 @@ if (actionOffset != 0) { LEReferenceTo<LigatureActionEntry> ap(stHeader, success, ligActionOffset); // byte offset - ap.addObject(ligActionIndex - 1, success); // index offset ( one before the actual start, because we will pre-increment) + ap.addObject(ligActionIndex, success); LEReferenceToArrayOf<TTGlyphID> ligatureTable(stHeader, success, ligatureOffset, LE_UNBOUNDED_ARRAY); LigatureActionEntry action; le_int32 offset, i = 0; @@ -111,7 +111,6 @@ do { le_uint32 componentGlyph = componentStack[m--]; // pop off - ap.addObject(success); action = SWAPL(*ap.getAlias()); if (m < 0) { @@ -145,7 +144,8 @@ LE_DEBUG_BAD_FONT("m<0") } #endif - } while (!(action & lafLast) && (m>=0) ); // stop if last bit is set, or if run out of items + ap.addObject(success); + } while (LE_SUCCESS(success) && !(action & lafLast) && (m>=0) ); // stop if last bit is set, or if run out of items while (mm >= 0) { if (++m >= nComponents) {
--- a/src/share/native/sun/font/layout/LookupProcessor.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/LookupProcessor.cpp Fri May 02 20:39:34 2014 +0100 @@ -282,6 +282,7 @@ for (le_uint16 feature = 0; feature < featureCount; feature += 1) { LEReferenceToArrayOf<le_uint16> featureIndexArray(langSysTable, success, langSysTable->featureIndexArray, featureCount); + if (LE_FAILURE(success)) { continue; } le_uint16 featureIndex = SWAPW(featureIndexArray.getObject(feature,success)); // don't add the required feature to the list more than once...
--- a/src/share/native/sun/font/layout/MarkToBasePosnSubtables.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/MarkToBasePosnSubtables.cpp Fri May 02 20:39:34 2014 +0100 @@ -67,6 +67,7 @@ LEPoint markAnchor; LEReferenceTo<MarkArray> markArray(base, success, (const MarkArray *) ((char *) this + SWAPW(markArrayOffset))); + if(LE_FAILURE(success)) return 0; le_int32 markClass = markArray->getMarkClass(markArray, markGlyph, markCoverage, fontInstance, markAnchor, success); le_uint16 mcCount = SWAPW(classCount);
--- a/src/share/native/sun/font/layout/OpenTypeUtilities.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/OpenTypeUtilities.cpp Fri May 02 20:39:34 2014 +0100 @@ -79,8 +79,8 @@ Offset OpenTypeUtilities::getTagOffset(LETag tag, const LEReferenceToArrayOf<TagAndOffsetRecord> &records, LEErrorCode &success) { + if(LE_FAILURE(success)) return 0; const TagAndOffsetRecord *r0 = (const TagAndOffsetRecord*)records.getAlias(); - if(LE_FAILURE(success)) return 0; le_uint32 recordCount = records.getCount(); le_uint8 bit = highBit(recordCount);
--- a/src/share/native/sun/font/layout/SegmentArrayProcessor.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/SegmentArrayProcessor.cpp Fri May 02 20:39:34 2014 +0100 @@ -73,6 +73,7 @@ if (offset != 0) { LEReferenceToArrayOf<TTGlyphID> glyphArray(subtableHeader, success, offset, LE_UNBOUNDED_ARRAY); + if (LE_FAILURE(success)) { continue; } TTGlyphID newGlyph = SWAPW(glyphArray(LE_GET_GLYPH(thisGlyph) - firstGlyph, success)); glyphStorage[glyph] = LE_SET_GLYPH(thisGlyph, newGlyph); }
--- a/src/share/native/sun/font/layout/StateTableProcessor.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/font/layout/StateTableProcessor.cpp Fri May 02 20:39:34 2014 +0100 @@ -97,6 +97,7 @@ LEReferenceToArrayOf<EntryTableIndex> stateArray(stHeader, success, currentState, LE_UNBOUNDED_ARRAY); EntryTableIndex entryTableIndex = stateArray.getObject((le_uint8)classCode, success); + if (LE_FAILURE(success)) { break; } LE_STATE_PATIENCE_CURR(le_int32, currGlyph); currentState = processStateEntry(glyphStorage, currGlyph, entryTableIndex); LE_STATE_PATIENCE_INCR(currGlyph);
--- a/src/share/native/sun/java2d/cmm/lcms/cmscam02.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmscam02.c Fri May 02 20:39:34 2014 +0100 @@ -81,7 +81,7 @@ cmsUInt32Number surround; cmsFloat64Number n, Nbb, Ncb, z, FL, D; - cmsContext ContextID; + cmsContext ContextID; } cmsCIECAM02; @@ -467,6 +467,7 @@ CAM02COLOR clr; cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel; + memset(&clr, 0, sizeof(clr)); _cmsAssert(lpMod != NULL); _cmsAssert(pIn != NULL); _cmsAssert(pOut != NULL); @@ -491,6 +492,7 @@ CAM02COLOR clr; cmsCIECAM02* lpMod = (cmsCIECAM02*) hModel; + memset(&clr, 0, sizeof(clr)); _cmsAssert(lpMod != NULL); _cmsAssert(pIn != NULL); _cmsAssert(pOut != NULL);
--- a/src/share/native/sun/java2d/cmm/lcms/cmscgats.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmscgats.c Fri May 02 20:39:34 2014 +0100 @@ -59,8 +59,8 @@ // IT8.7 / CGATS.17-200x handling ----------------------------------------------------------------------------- -#define MAXID 128 // Max lenght of identifier -#define MAXSTR 1024 // Max lenght of string +#define MAXID 128 // Max length of identifier +#define MAXSTR 1024 // Max length of string #define MAXTABLES 255 // Max Number of tables in a single stream #define MAXINCLUDE 20 // Max number of nested includes @@ -383,28 +383,28 @@ //Forward declaration of some internal functions static void* AllocChunk(cmsIT8* it8, cmsUInt32Number size); -// Checks if c is a separator +// Checks whatever c is a separator static cmsBool isseparator(int c) { - return (c == ' ') || (c == '\t') || (c == '\r'); + return (c == ' ') || (c == '\t') ; } -// Checks whatever if c is a valid identifier char +// Checks whatever c is a valid identifier char static cmsBool ismiddle(int c) { return (!isseparator(c) && (c != '#') && (c !='\"') && (c != '\'') && (c > 32) && (c < 127)); } -// Checks whatsever if c is a valid identifier middle char. +// Checks whatsever c is a valid identifier middle char. static cmsBool isidchar(int c) { return isalnum(c) || ismiddle(c); } -// Checks whatsever if c is a valid identifier first char. +// Checks whatsever c is a valid identifier first char. static cmsBool isfirstidchar(int c) { @@ -436,7 +436,6 @@ } - // Makes a file path based on a given reference path // NOTE: this function doesn't check if the path exists or even if it's legal static @@ -634,6 +633,9 @@ cmsFloat64Number dnum = 0.0; int sign = 1; + // keep safe + if (Buffer == NULL) return 0.0; + if (*Buffer == '-' || *Buffer == '+') { sign = (*Buffer == '-') ? -1 : 1; @@ -867,6 +869,14 @@ // Next line + case '\r': + NextCh(it8); + if (it8 ->ch == '\n') + NextCh(it8); + it8->sy = SEOLN; + it8->lineno++; + break; + case '\n': NextCh(it8); it8->sy = SEOLN; @@ -876,7 +886,7 @@ // Comment case '#': NextCh(it8); - while (it8->ch && it8->ch != '\n') + while (it8->ch && it8->ch != '\n' && it8->ch != '\r') NextCh(it8); it8->sy = SCOMMENT; @@ -994,6 +1004,9 @@ { switch (it8->sy) { + case SEOLN: // Empty value + Buffer[0]=0; + break; case SIDENT: strncpy(Buffer, it8->id, max); Buffer[max-1]=0; break; @@ -1143,9 +1156,9 @@ if (*Key != '#') { // Comments are ignored if (cmsstrcasecmp(Key, p->Keyword) == 0) - break; + break; } - } + } if (p == NULL) return FALSE; @@ -1155,11 +1168,13 @@ for (; p != NULL; p = p->NextSubkey) { + if (p ->Subkey == NULL) continue; + if (LastPtr) *LastPtr = p; if (cmsstrcasecmp(Subkey, p->Subkey) == 0) - return TRUE; - } + return TRUE; + } return FALSE; } @@ -1282,7 +1297,7 @@ it8 ->nTable = nTable; - return nTable; + return (cmsInt32Number) nTable; } @@ -1387,7 +1402,7 @@ cmsIT8* it8 = (cmsIT8*) hIT8; char Buffer[1024]; - sprintf(Buffer, "%d", Val); + sprintf(Buffer, "%u", Val); return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_HEXADECIMAL) != NULL; } @@ -1424,6 +1439,8 @@ { const char *v = cmsIT8GetProperty(hIT8, cProp); + if (v == NULL) return 0.0; + return ParseFloatNumber(v); } @@ -1456,7 +1473,7 @@ t -> nSamples = 10; } - t -> DataFormat = (char**) AllocChunk (it8, (t->nSamples + 1) * sizeof(char *)); + t -> DataFormat = (char**) AllocChunk (it8, ((cmsUInt32Number) t->nSamples + 1) * sizeof(char *)); if (t->DataFormat == NULL) { SynError(it8, "AllocateDataFormat: Unable to allocate dataFormat array"); @@ -1512,7 +1529,7 @@ t-> nSamples = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS")); t-> nPatches = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS")); - t-> Data = (char**)AllocChunk (it8, (t->nSamples + 1) * (t->nPatches + 1) *sizeof (char*)); + t-> Data = (char**)AllocChunk (it8, ((cmsUInt32Number) t->nSamples + 1) * ((cmsUInt32Number) t->nPatches + 1) *sizeof (char*)); if (t->Data == NULL) { SynError(it8, "AllocateDataSet: Unable to allocate data array"); @@ -1571,7 +1588,7 @@ if (str == NULL) str = " "; - // Lenghth to write + // Length to write len = (cmsUInt32Number) strlen(str); f ->Used += len; @@ -2095,7 +2112,7 @@ NextCh(it8); // If a newline is found, then this is a type string - if (it8 ->ch == '\n') { + if (it8 ->ch == '\n' || it8->ch == '\r') { cmsIT8SetSheetType(it8, it8 ->id); InSymbol(it8); @@ -2210,7 +2227,7 @@ char Buffer[256]; char *Type = p ->Value; - int nTable = k; + int nTable = (int) k; snprintf(Buffer, 255, "%s %d %s", Label, nTable, Type ); @@ -2564,6 +2581,8 @@ Buffer = cmsIT8GetDataRowCol(hIT8, row, col); + if (Buffer == NULL) return 0.0; + return ParseFloatNumber(Buffer); } @@ -2776,7 +2795,7 @@ if (Formatter == NULL) strcpy(it8->DoubleFormatter, DEFAULT_DBL_FORMAT); else - strcpy(it8->DoubleFormatter, Formatter); + strncpy(it8->DoubleFormatter, Formatter, sizeof(it8->DoubleFormatter)); it8 ->DoubleFormatter[sizeof(it8 ->DoubleFormatter)-1] = 0; }
--- a/src/share/native/sun/java2d/cmm/lcms/cmscnvrt.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmscnvrt.c Fri May 02 20:39:34 2014 +0100 @@ -270,7 +270,7 @@ // m2 holds CHAD from output white to D50 times abs. col. scaling // Observer is not adapted, undo the chromatic adaptation - _cmsMAT3per(m, &m3, ChromaticAdaptationMatrixOut); + _cmsMAT3per(m, &m2, ChromaticAdaptationMatrixOut); m3 = *ChromaticAdaptationMatrixIn; if (!_cmsMAT3inverse(&m3, &m4)) return FALSE; @@ -411,57 +411,61 @@ // Handle PCS mismatches. A specialized stage is added to the LUT in such case switch (InPCS) { - case cmsSigXYZData: // Input profile operates in XYZ - - switch (OutPCS) { + case cmsSigXYZData: // Input profile operates in XYZ - case cmsSigXYZData: // XYZ -> XYZ - if (!IsEmptyLayer(m, off)) - cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)); - break; + switch (OutPCS) { - case cmsSigLabData: // XYZ -> Lab - if (!IsEmptyLayer(m, off)) - cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)); - cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocXYZ2Lab(Result ->ContextID)); - break; + case cmsSigXYZData: // XYZ -> XYZ + if (!IsEmptyLayer(m, off) && + !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl))) + return FALSE; + break; - default: - return FALSE; // Colorspace mismatch - } - break; - + case cmsSigLabData: // XYZ -> Lab + if (!IsEmptyLayer(m, off) && + !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl))) + return FALSE; + if (!cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocXYZ2Lab(Result ->ContextID))) + return FALSE; + break; - case cmsSigLabData: // Input profile operates in Lab - - switch (OutPCS) { + default: + return FALSE; // Colorspace mismatch + } + break; - case cmsSigXYZData: // Lab -> XYZ + case cmsSigLabData: // Input profile operates in Lab - cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocLab2XYZ(Result ->ContextID)); - if (!IsEmptyLayer(m, off)) - cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)); - break; + switch (OutPCS) { + + case cmsSigXYZData: // Lab -> XYZ - case cmsSigLabData: // Lab -> Lab + if (!cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocLab2XYZ(Result ->ContextID))) + return FALSE; + if (!IsEmptyLayer(m, off) && + !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl))) + return FALSE; + break; - if (!IsEmptyLayer(m, off)) { - cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocLab2XYZ(Result ->ContextID)); - cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)); - cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocXYZ2Lab(Result ->ContextID)); - } - break; + case cmsSigLabData: // Lab -> Lab - default: - return FALSE; // Mismatch + if (!IsEmptyLayer(m, off)) { + if (!cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocLab2XYZ(Result ->ContextID)) || + !cmsPipelineInsertStage(Result, cmsAT_END, cmsStageAllocMatrix(Result ->ContextID, 3, 3, m_as_dbl, off_as_dbl)) || + !cmsPipelineInsertStage(Result, cmsAT_END, _cmsStageAllocXYZ2Lab(Result ->ContextID))) + return FALSE; } break; + default: + return FALSE; // Mismatch + } + break; - // On colorspaces other than PCS, check for same space - default: - if (InPCS != OutPCS) return FALSE; - break; + // On colorspaces other than PCS, check for same space + default: + if (InPCS != OutPCS) return FALSE; + break; } return TRUE; @@ -497,7 +501,8 @@ cmsFloat64Number AdaptationStates[], cmsUInt32Number dwFlags) { - cmsPipeline* Lut, *Result; + cmsPipeline* Lut = NULL; + cmsPipeline* Result; cmsHPROFILE hProfile; cmsMAT3 m; cmsVEC3 off; @@ -593,8 +598,11 @@ } // Concatenate to the output LUT - cmsPipelineCat(Result, Lut); + if (!cmsPipelineCat(Result, Lut)) + goto Error; + cmsPipelineFree(Lut); + Lut = NULL; // Update current space CurrentColorSpace = ColorSpaceOut; @@ -604,6 +612,7 @@ Error: + if (Lut != NULL) cmsPipelineFree(Lut); if (Result != NULL) cmsPipelineFree(Result); return NULL; @@ -742,7 +751,8 @@ if (CLUT == NULL) goto Error; // This is the one and only MPE in this LUT - cmsPipelineInsertStage(Result, cmsAT_BEGIN, CLUT); + if (!cmsPipelineInsertStage(Result, cmsAT_BEGIN, CLUT)) + goto Error; // Sample it. We cannot afford pre/post linearization this time. if (!cmsStageSampleCLut16bit(CLUT, BlackPreservingGrayOnlySampler, (void*) &bp, 0)) @@ -959,7 +969,8 @@ CLUT = cmsStageAllocCLut16bit(ContextID, nGridPoints, 4, 4, NULL); if (CLUT == NULL) goto Cleanup; - cmsPipelineInsertStage(Result, cmsAT_BEGIN, CLUT); + if (!cmsPipelineInsertStage(Result, cmsAT_BEGIN, CLUT)) + goto Cleanup; cmsStageSampleCLut16bit(CLUT, BlackPreservingSampler, (void*) &bp, 0); @@ -1057,7 +1068,7 @@ } // The plug-in registration. User can add new intents or override default routines -cmsBool _cmsRegisterRenderingIntentPlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterRenderingIntentPlugin(cmsContext id, cmsPluginBase* Data) { cmsPluginRenderingIntent* Plugin = (cmsPluginRenderingIntent*) Data; cmsIntentsList* fl; @@ -1072,7 +1083,7 @@ fl = SearchIntent(Plugin ->Intent); if (fl == NULL) { - fl = (cmsIntentsList*) _cmsPluginMalloc(sizeof(cmsIntentsList)); + fl = (cmsIntentsList*) _cmsPluginMalloc(id, sizeof(cmsIntentsList)); if (fl == NULL) return FALSE; }
--- a/src/share/native/sun/java2d/cmm/lcms/cmserr.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmserr.c Fri May 02 20:39:34 2014 +0100 @@ -302,8 +302,6 @@ return NULL; } - - chunk ->BlockSize = Initial; chunk ->Used = 0; chunk ->next = NULL;
--- a/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsgamma.c Fri May 02 20:39:34 2014 +0100 @@ -30,7 +30,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2013 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -99,7 +99,7 @@ static _cmsParametricCurvesCollection* ParametricCurves = &DefaultCurves; // As a way to install new parametric curves -cmsBool _cmsRegisterParametricCurvesPlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterParametricCurvesPlugin(cmsContext id, cmsPluginBase* Data) { cmsPluginParametricCurves* Plugin = (cmsPluginParametricCurves*) Data; _cmsParametricCurvesCollection* fl; @@ -110,7 +110,7 @@ return TRUE; } - fl = (_cmsParametricCurvesCollection*) _cmsPluginMalloc(sizeof(_cmsParametricCurvesCollection)); + fl = (_cmsParametricCurvesCollection*) _cmsPluginMalloc(id, sizeof(_cmsParametricCurvesCollection)); if (fl == NULL) return FALSE; // Copy the parameters @@ -258,7 +258,8 @@ } p ->InterpParams = _cmsComputeInterpParams(ContextID, p ->nEntries, 1, 1, p->Table16, CMS_LERP_FLAGS_16BITS); - return p; + if (p->InterpParams != NULL) + return p; Error: if (p -> Segments) _cmsFree(ContextID, p ->Segments); @@ -423,7 +424,7 @@ if (e > 0) Val = pow(e, Params[0]) + Params[5]; else - Val = 0; + Val = Params[5]; } else Val = R*Params[3] + Params[6]; @@ -458,7 +459,7 @@ e = Params[1]*R + Params[2]; if (e < 0) - Val = 0; + Val = Params[3]; else Val = pow(e, Params[0]) + Params[3]; break; @@ -478,7 +479,7 @@ e = Params[2] * pow(R, Params[0]) + Params[3]; if (e <= 0) - Val = 0; + Val = Params[4]; else Val = Params[1]*log10(e) + Params[4]; break; @@ -544,7 +545,7 @@ // Type == 0 means segment is sampled if (g ->Segments[i].Type == 0) { - cmsFloat32Number R1 = (cmsFloat32Number) (R - g ->Segments[i].x0); + cmsFloat32Number R1 = (cmsFloat32Number) (R - g ->Segments[i].x0) / (g ->Segments[i].x1 - g ->Segments[i].x0); cmsFloat32Number Out; // Setup the table (TODO: clean that) @@ -629,20 +630,21 @@ // Use a segmented curve to store the floating point table cmsToneCurve* CMSEXPORT cmsBuildTabulatedToneCurveFloat(cmsContext ContextID, cmsUInt32Number nEntries, const cmsFloat32Number values[]) { - cmsCurveSegment Seg[2]; + cmsCurveSegment Seg[3]; - // Initialize segmented curve part up to 0 - Seg[0].x0 = -1; + // A segmented tone curve should have function segments in the first and last positions + // Initialize segmented curve part up to 0 to constant value = samples[0] + Seg[0].x0 = MINUS_INF; Seg[0].x1 = 0; Seg[0].Type = 6; Seg[0].Params[0] = 1; Seg[0].Params[1] = 0; Seg[0].Params[2] = 0; - Seg[0].Params[3] = 0; + Seg[0].Params[3] = values[0]; Seg[0].Params[4] = 0; - // From zero to any + // From zero to 1 Seg[1].x0 = 0; Seg[1].x1 = 1.0; Seg[1].Type = 0; @@ -650,7 +652,19 @@ Seg[1].nGridPoints = nEntries; Seg[1].SampledPoints = (cmsFloat32Number*) values; - return cmsBuildSegmentedToneCurve(ContextID, 2, Seg); + // Final segment is constant = lastsample + Seg[2].x0 = 1.0; + Seg[2].x1 = PLUS_INF; + Seg[2].Type = 6; + + Seg[2].Params[0] = 1; + Seg[2].Params[1] = 0; + Seg[2].Params[2] = 0; + Seg[2].Params[3] = values[nEntries-1]; + Seg[2].Params[4] = 0; + + + return cmsBuildSegmentedToneCurve(ContextID, 3, Seg); } // Parametric curves @@ -993,7 +1007,7 @@ if (Tab == NULL) return FALSE; - if (cmsIsToneCurveLinear(Tab)) return FALSE; // Nothing to do + if (cmsIsToneCurveLinear(Tab)) return TRUE; // Nothing to do nItems = Tab -> nEntries; @@ -1020,11 +1034,20 @@ if (z[i] == 0.) Zeros++; if (z[i] >= 65535.) Poles++; - if (z[i] < z[i-1]) return FALSE; // Non-Monotonic + if (z[i] < z[i-1]) { + cmsSignalError(Tab ->InterpParams->ContextID, cmsERROR_RANGE, "cmsSmoothToneCurve: Non-Monotonic."); + return FALSE; + } } - if (Zeros > (nItems / 3)) return FALSE; // Degenerated, mostly zeros - if (Poles > (nItems / 3)) return FALSE; // Degenerated, mostly poles + if (Zeros > (nItems / 3)) { + cmsSignalError(Tab ->InterpParams->ContextID, cmsERROR_RANGE, "cmsSmoothToneCurve: Degenerated, mostly zeros."); + return FALSE; + } + if (Poles > (nItems / 3)) { + cmsSignalError(Tab ->InterpParams->ContextID, cmsERROR_RANGE, "cmsSmoothToneCurve: Degenerated, mostly poles."); + return FALSE; + } // Seems ok for (i=0; i < nItems; i++) {
--- a/src/share/native/sun/java2d/cmm/lcms/cmsgmt.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsgmt.c Fri May 02 20:39:34 2014 +0100 @@ -249,13 +249,10 @@ cmsFloat64Number dE1, dE2, ErrorRatio; // Assume in-gamut by default. - dE1 = 0.; - dE2 = 0; ErrorRatio = 1.0; // Convert input to Lab - if (t -> hInput != NULL) - cmsDoTransform(t -> hInput, In, &LabIn1, 1); + cmsDoTransform(t -> hInput, In, &LabIn1, 1); // converts from PCS to colorant. This always // does return in-gamut values, @@ -267,7 +264,7 @@ memmove(&LabIn2, &LabOut1, sizeof(cmsCIELab)); // Try again, but this time taking Check as input - cmsDoTransform(t -> hForward, &LabOut1, Proof2, 1); + cmsDoTransform(t -> hForward, &LabOut1, Proof2, 1); cmsDoTransform(t -> hReverse, Proof2, &LabOut2, 1); // Take difference of direct value @@ -374,7 +371,7 @@ ProfileList[nGamutPCSposition] = hLab; BPCList[nGamutPCSposition] = 0; AdaptationList[nGamutPCSposition] = 1.0; - Intents[nGamutPCSposition] = INTENT_RELATIVE_COLORIMETRIC; + IntentList[nGamutPCSposition] = INTENT_RELATIVE_COLORIMETRIC; ColorSpace = cmsGetColorSpace(hGamut); @@ -385,45 +382,48 @@ // 16 bits to Lab double Chain.hInput = cmsCreateExtendedTransform(ContextID, - nGamutPCSposition + 1, - ProfileList, - BPCList, - Intents, - AdaptationList, - NULL, 0, - dwFormat, TYPE_Lab_DBL, - cmsFLAGS_NOCACHE); + nGamutPCSposition + 1, + ProfileList, + BPCList, + IntentList, + AdaptationList, + NULL, 0, + dwFormat, TYPE_Lab_DBL, + cmsFLAGS_NOCACHE); // Does create the forward step. Lab double to device dwFormat = (CHANNELS_SH(nChannels)|BYTES_SH(2)); Chain.hForward = cmsCreateTransformTHR(ContextID, - hLab, TYPE_Lab_DBL, - hGamut, dwFormat, - INTENT_RELATIVE_COLORIMETRIC, - cmsFLAGS_NOCACHE); + hLab, TYPE_Lab_DBL, + hGamut, dwFormat, + INTENT_RELATIVE_COLORIMETRIC, + cmsFLAGS_NOCACHE); // Does create the backwards step Chain.hReverse = cmsCreateTransformTHR(ContextID, hGamut, dwFormat, - hLab, TYPE_Lab_DBL, - INTENT_RELATIVE_COLORIMETRIC, - cmsFLAGS_NOCACHE); + hLab, TYPE_Lab_DBL, + INTENT_RELATIVE_COLORIMETRIC, + cmsFLAGS_NOCACHE); // All ok? - if (Chain.hForward && Chain.hReverse) { + if (Chain.hInput && Chain.hForward && Chain.hReverse) { // Go on, try to compute gamut LUT from PCS. This consist on a single channel containing // dE when doing a transform back and forth on the colorimetric intent. Gamut = cmsPipelineAlloc(ContextID, 3, 1); - if (Gamut != NULL) { - CLUT = cmsStageAllocCLut16bit(ContextID, nGridpoints, nChannels, 1, NULL); - cmsPipelineInsertStage(Gamut, cmsAT_BEGIN, CLUT); - - cmsStageSampleCLut16bit(CLUT, GamutSampler, (void*) &Chain, 0); + CLUT = cmsStageAllocCLut16bit(ContextID, nGridpoints, nChannels, 1, NULL); + if (!cmsPipelineInsertStage(Gamut, cmsAT_BEGIN, CLUT)) { + cmsPipelineFree(Gamut); + Gamut = NULL; + } + else { + cmsStageSampleCLut16bit(CLUT, GamutSampler, (void*) &Chain, 0); + } } } else
--- a/src/share/native/sun/java2d/cmm/lcms/cmsintrp.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsintrp.c Fri May 02 20:39:34 2014 +0100 @@ -83,7 +83,6 @@ // Set the interpolation method - cmsBool _cmsSetInterpolationRoutine(cmsInterpParams* p) { // Invoke factory, possibly in the Plug-in @@ -215,6 +214,11 @@ Output[0] = LinearInterp(rest, y0, y1); } +// To prevent out of bounds indexing +cmsINLINE cmsFloat32Number fclamp(cmsFloat32Number v) +{ + return v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v); +} // Floating-point version of 1D interpolation static @@ -227,13 +231,15 @@ int cell0, cell1; const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table; + val2 = fclamp(Value[0]); + // if last value... - if (Value[0] == 1.0) { + if (val2 == 1.0) { Output[0] = LutTable[p -> Domain[0]]; return; } - val2 = p -> Domain[0] * Value[0]; + val2 *= p -> Domain[0]; cell0 = (int) floor(val2); cell1 = (int) ceil(val2); @@ -292,13 +298,15 @@ cmsUInt32Number OutChan; const cmsFloat32Number* LutTable = (cmsFloat32Number*) p ->Table; + val2 = fclamp(Value[0]); + // if last value... - if (Value[0] == 1.0) { + if (val2 == 1.0) { Output[0] = LutTable[p -> Domain[0]]; return; } - val2 = p -> Domain[0] * Value[0]; + val2 *= p -> Domain[0]; cell0 = (int) floor(val2); cell1 = (int) ceil(val2); @@ -339,8 +347,8 @@ dxy; TotalOut = p -> nOutputs; - px = Input[0] * p->Domain[0]; - py = Input[1] * p->Domain[1]; + px = fclamp(Input[0]) * p->Domain[0]; + py = fclamp(Input[1]) * p->Domain[1]; x0 = (int) _cmsQuickFloor(px); fx = px - (cmsFloat32Number) x0; y0 = (int) _cmsQuickFloor(py); fy = py - (cmsFloat32Number) y0; @@ -454,20 +462,9 @@ TotalOut = p -> nOutputs; // We need some clipping here - px = Input[0]; - py = Input[1]; - pz = Input[2]; - - if (px < 0) px = 0; - if (px > 1) px = 1; - if (py < 0) py = 0; - if (py > 1) py = 1; - if (pz < 0) pz = 0; - if (pz > 1) pz = 1; - - px *= p->Domain[0]; - py *= p->Domain[1]; - pz *= p->Domain[2]; + px = fclamp(Input[0]) * p->Domain[0]; + py = fclamp(Input[1]) * p->Domain[1]; + pz = fclamp(Input[2]) * p->Domain[2]; x0 = (int) _cmsQuickFloor(px); fx = px - (cmsFloat32Number) x0; y0 = (int) _cmsQuickFloor(py); fy = py - (cmsFloat32Number) y0; @@ -609,20 +606,9 @@ TotalOut = p -> nOutputs; // We need some clipping here - px = Input[0]; - py = Input[1]; - pz = Input[2]; - - if (px < 0) px = 0; - if (px > 1) px = 1; - if (py < 0) py = 0; - if (py > 1) py = 1; - if (pz < 0) pz = 0; - if (pz > 1) pz = 1; - - px *= p->Domain[0]; - py *= p->Domain[1]; - pz *= p->Domain[2]; + px = fclamp(Input[0]) * p->Domain[0]; + py = fclamp(Input[1]) * p->Domain[1]; + pz = fclamp(Input[2]) * p->Domain[2]; x0 = (int) _cmsQuickFloor(px); rx = (px - (cmsFloat32Number) x0); y0 = (int) _cmsQuickFloor(py); ry = (py - (cmsFloat32Number) y0); @@ -844,7 +830,7 @@ register cmsUInt16Number Output[], register const cmsInterpParams* p16) { - const cmsUInt16Number* LutTable = (cmsUInt16Number*) p16 -> Table; + const cmsUInt16Number* LutTable; cmsS15Fixed16Number fk; cmsS15Fixed16Number k0, rk; int K0, K1; @@ -1039,8 +1025,7 @@ cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS]; cmsInterpParams p1; - - pk = Input[0] * p->Domain[0]; + pk = fclamp(Input[0]) * p->Domain[0]; k0 = _cmsQuickFloor(pk); rest = pk - (cmsFloat32Number) k0; @@ -1127,7 +1112,7 @@ cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS]; cmsInterpParams p1; - pk = Input[0] * p->Domain[0]; + pk = fclamp(Input[0]) * p->Domain[0]; k0 = _cmsQuickFloor(pk); rest = pk - (cmsFloat32Number) k0; @@ -1214,7 +1199,7 @@ cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS]; cmsInterpParams p1; - pk = Input[0] * p->Domain[0]; + pk = fclamp(Input[0]) * p->Domain[0]; k0 = _cmsQuickFloor(pk); rest = pk - (cmsFloat32Number) k0; @@ -1299,7 +1284,7 @@ cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS]; cmsInterpParams p1; - pk = Input[0] * p->Domain[0]; + pk = fclamp(Input[0]) * p->Domain[0]; k0 = _cmsQuickFloor(pk); rest = pk - (cmsFloat32Number) k0; @@ -1384,7 +1369,7 @@ cmsFloat32Number Tmp1[MAX_STAGE_CHANNELS], Tmp2[MAX_STAGE_CHANNELS]; cmsInterpParams p1; - pk = Input[0] * p->Domain[0]; + pk = fclamp(Input[0]) * p->Domain[0]; k0 = _cmsQuickFloor(pk); rest = pk - (cmsFloat32Number) k0;
--- a/src/share/native/sun/java2d/cmm/lcms/cmsio0.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsio0.c Fri May 02 20:39:34 2014 +0100 @@ -154,7 +154,6 @@ return iohandler; Error: - if (fm) _cmsFree(ContextID, fm); if (iohandler) _cmsFree(ContextID, iohandler); return NULL; @@ -223,12 +222,17 @@ // Writes data to memory, also keeps used space for further reference. static -cmsBool MemoryWrite(struct _cms_io_handler* iohandler, cmsUInt32Number size, const void *Ptr) +cmsBool MemoryWrite(struct _cms_io_handler* iohandler, cmsUInt32Number size, const void *Ptr) { FILEMEM* ResData = (FILEMEM*) iohandler ->stream; if (ResData == NULL) return FALSE; // Housekeeping + // Check for available space. Clip. + if (iohandler ->UsedSpace + size > ResData->Size) { + size = ResData ->Size - iohandler ->UsedSpace; + } + if (size == 0) return TRUE; // Write zero bytes is ok, but does nothing memmove(ResData ->Block + ResData ->Pointer, Ptr, size); @@ -389,13 +393,15 @@ return TRUE; } -// Create a iohandler for disk based files. if FileName is NULL, then 'stream' member is also set -// to NULL and no real writting is performed. This only happens in writting access mode +// Create a iohandler for disk based files. cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromFile(cmsContext ContextID, const char* FileName, const char* AccessMode) { cmsIOHANDLER* iohandler = NULL; FILE* fm = NULL; + _cmsAssert(FileName != NULL); + _cmsAssert(AccessMode != NULL); + iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER)); if (iohandler == NULL) return NULL; @@ -432,11 +438,8 @@ iohandler ->UsedSpace = 0; // Keep track of the original file - if (FileName != NULL) { - - strncpy(iohandler -> PhysicalFile, FileName, sizeof(iohandler -> PhysicalFile)-1); - iohandler -> PhysicalFile[sizeof(iohandler -> PhysicalFile)-1] = 0; - } + strncpy(iohandler -> PhysicalFile, FileName, sizeof(iohandler -> PhysicalFile)-1); + iohandler -> PhysicalFile[sizeof(iohandler -> PhysicalFile)-1] = 0; iohandler ->Read = FileRead; iohandler ->Seek = FileSeek; @@ -616,6 +619,31 @@ return _cmsSearchTag(Icc, sig, FALSE) >= 0; } +/* + * Enforces that the profile version is per. spec. + * Operates on the big endian bytes from the profile. + * Called before converting to platform endianness. + * Byte 0 is BCD major version, so max 9. + * Byte 1 is 2 BCD digits, one per nibble. + * Reserved bytes 2 & 3 must be 0. + */ +static cmsUInt32Number _validatedVersion(cmsUInt32Number DWord) +{ + cmsUInt8Number* pByte = (cmsUInt8Number*)&DWord; + cmsUInt8Number temp1; + cmsUInt8Number temp2; + + if (*pByte > 0x09) *pByte = (cmsUInt8Number)9; + temp1 = *(pByte+1) & 0xf0; + temp2 = *(pByte+1) & 0x0f; + if (temp1 > 0x90) temp1 = 0x90; + if (temp2 > 9) temp2 = 0x09; + *(pByte+1) = (cmsUInt8Number)(temp1 | temp2); + *(pByte+2) = (cmsUInt8Number)0; + *(pByte+3) = (cmsUInt8Number)0; + + return DWord; +} // Read profile header and validate it cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc) @@ -643,12 +671,15 @@ Icc -> DeviceClass = (cmsProfileClassSignature) _cmsAdjustEndianess32(Header.deviceClass); Icc -> ColorSpace = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.colorSpace); Icc -> PCS = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.pcs); + Icc -> RenderingIntent = _cmsAdjustEndianess32(Header.renderingIntent); Icc -> flags = _cmsAdjustEndianess32(Header.flags); Icc -> manufacturer = _cmsAdjustEndianess32(Header.manufacturer); Icc -> model = _cmsAdjustEndianess32(Header.model); + Icc -> creator = _cmsAdjustEndianess32(Header.creator); + _cmsAdjustEndianess64(&Icc -> attributes, &Header.attributes); - Icc -> Version = _cmsAdjustEndianess32(Header.version); + Icc -> Version = _cmsAdjustEndianess32(_validatedVersion(Header.version)); // Get size as reported in header HeaderSize = _cmsAdjustEndianess32(Header.size); @@ -815,28 +846,33 @@ cmsUInt32Number CMSEXPORT cmsGetHeaderManufacturer(cmsHPROFILE hProfile) { _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; - return (cmsUInt32Number) Icc ->manufacturer; + return Icc ->manufacturer; } void CMSEXPORT cmsSetHeaderManufacturer(cmsHPROFILE hProfile, cmsUInt32Number manufacturer) { _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; - Icc -> manufacturer = (cmsUInt32Number) manufacturer; + Icc -> manufacturer = manufacturer; +} + +cmsUInt32Number CMSEXPORT cmsGetHeaderCreator(cmsHPROFILE hProfile) +{ + _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; + return Icc ->creator; } cmsUInt32Number CMSEXPORT cmsGetHeaderModel(cmsHPROFILE hProfile) { _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; - return (cmsUInt32Number) Icc ->model; + return Icc ->model; } void CMSEXPORT cmsSetHeaderModel(cmsHPROFILE hProfile, cmsUInt32Number model) { _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; - Icc -> model = (cmsUInt32Number) model; + Icc -> model = model; } - void CMSEXPORT cmsGetHeaderAttributes(cmsHPROFILE hProfile, cmsUInt64Number* Flags) { _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; @@ -1073,11 +1109,16 @@ return cmsOpenProfileFromMemTHR(NULL, MemPtr, dwSize); } - static cmsBool SanityCheck(_cmsICCPROFILE* profile) { - cmsIOHANDLER* io = profile->IOhandler; + cmsIOHANDLER* io; + + if (!profile) { + return FALSE; + } + + io = profile->IOhandler; if (!io) { return FALSE; } @@ -1106,13 +1147,13 @@ cmsIOHANDLER* io = Icc ->IOhandler; cmsTagDescriptor* TagDescriptor; cmsTagTypeSignature TypeBase; + cmsTagTypeSignature Type; cmsTagTypeHandler* TypeHandler; - - if (!SanityCheck(FileOrig)) return FALSE; + cmsFloat64Number Version = cmsGetProfileVersion((cmsHPROFILE) Icc); + cmsTagTypeHandler LocalTypeHandler; for (i=0; i < Icc -> TagCount; i++) { - if (Icc ->TagNames[i] == 0) continue; // Linked tags are not written @@ -1126,7 +1167,7 @@ // Reach here if we are copying a tag from a disk-based ICC profile which has not been modified by user. // In this case a blind copy of the block data is performed - if (FileOrig != NULL && Icc -> TagOffsets[i]) { + if (SanityCheck(FileOrig) && Icc -> TagOffsets[i]) { cmsUInt32Number TagSize = FileOrig -> TagSizes[i]; cmsUInt32Number TagOffset = FileOrig -> TagOffsets[i]; @@ -1164,7 +1205,16 @@ TagDescriptor = _cmsGetTagDescriptor(Icc -> TagNames[i]); if (TagDescriptor == NULL) continue; // Unsupported, ignore it - TypeHandler = Icc ->TagTypeHandlers[i]; + if (TagDescriptor ->DecideType != NULL) { + + Type = TagDescriptor ->DecideType(Version, Data); + } + else { + + Type = TagDescriptor ->SupportedTypes[0]; + } + + TypeHandler = _cmsGetTagTypeHandler(Type); if (TypeHandler == NULL) { cmsSignalError(Icc ->ContextID, cmsERROR_INTERNAL, "(Internal) no handler for tag %x", Icc -> TagNames[i]); @@ -1175,9 +1225,10 @@ if (!_cmsWriteTypeBase(io, TypeBase)) return FALSE; - TypeHandler ->ContextID = Icc ->ContextID; - TypeHandler ->ICCVersion = Icc ->Version; - if (!TypeHandler ->WritePtr(TypeHandler, io, Data, TagDescriptor ->ElemCount)) { + LocalTypeHandler = *TypeHandler; + LocalTypeHandler.ContextID = Icc ->ContextID; + LocalTypeHandler.ICCVersion = Icc ->Version; + if (!LocalTypeHandler.WritePtr(&LocalTypeHandler, io, Data, TagDescriptor ->ElemCount)) { char String[5]; @@ -1314,8 +1365,8 @@ // Should we just calculate the needed space? if (MemPtr == NULL) { - *BytesNeeded = cmsSaveProfileToIOhandler(hProfile, NULL); - return (*BytesNeeded == 0 ? FALSE : TRUE); + *BytesNeeded = cmsSaveProfileToIOhandler(hProfile, NULL); + return (*BytesNeeded == 0 ? FALSE : TRUE); } // That is a real write operation @@ -1353,10 +1404,11 @@ cmsTagTypeHandler* TypeHandler = Icc ->TagTypeHandlers[i]; if (TypeHandler != NULL) { + cmsTagTypeHandler LocalTypeHandler = *TypeHandler; - TypeHandler ->ContextID = Icc ->ContextID; // As an additional parameters - TypeHandler ->ICCVersion = Icc ->Version; - TypeHandler ->FreePtr(TypeHandler, Icc -> TagPtrs[i]); + LocalTypeHandler.ContextID = Icc ->ContextID; // As an additional parameters + LocalTypeHandler.ICCVersion = Icc ->Version; + LocalTypeHandler.FreePtr(&LocalTypeHandler, Icc -> TagPtrs[i]); } else _cmsFree(Icc ->ContextID, Icc ->TagPtrs[i]); @@ -1400,6 +1452,7 @@ _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; cmsIOHANDLER* io = Icc ->IOhandler; cmsTagTypeHandler* TypeHandler; + cmsTagTypeHandler LocalTypeHandler; cmsTagDescriptor* TagDescriptor; cmsTagTypeSignature BaseType; cmsUInt32Number Offset, TagSize; @@ -1423,7 +1476,7 @@ // Seek to its location if (!io -> Seek(io, Offset)) - return NULL; + return NULL; // Search for support on this tag TagDescriptor = _cmsGetTagDescriptor(sig); @@ -1440,14 +1493,15 @@ // Get type handler TypeHandler = _cmsGetTagTypeHandler(BaseType); if (TypeHandler == NULL) return NULL; + LocalTypeHandler = *TypeHandler; // Read the tag Icc -> TagTypeHandlers[n] = TypeHandler; - TypeHandler ->ContextID = Icc ->ContextID; - TypeHandler ->ICCVersion = Icc ->Version; - Icc -> TagPtrs[n] = TypeHandler ->ReadPtr(TypeHandler, io, &ElemCount, TagSize); + LocalTypeHandler.ContextID = Icc ->ContextID; + LocalTypeHandler.ICCVersion = Icc ->Version; + Icc -> TagPtrs[n] = LocalTypeHandler.ReadPtr(&LocalTypeHandler, io, &ElemCount, TagSize); // The tag type is supported, but something wrong happend and we cannot read the tag. // let know the user about this (although it is just a warning) @@ -1468,7 +1522,7 @@ _cmsTagSignature2String(String, sig); cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "'%s' Inconsistent number of items: expected %d, got %d", - String, TagDescriptor ->ElemCount, ElemCount); + String, TagDescriptor ->ElemCount, ElemCount); } @@ -1500,6 +1554,7 @@ { _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; cmsTagTypeHandler* TypeHandler = NULL; + cmsTagTypeHandler LocalTypeHandler; cmsTagDescriptor* TagDescriptor = NULL; cmsTagTypeSignature Type; int i; @@ -1530,9 +1585,10 @@ if (TypeHandler != NULL) { - TypeHandler ->ContextID = Icc ->ContextID; // As an additional parameter - TypeHandler ->ICCVersion = Icc ->Version; - TypeHandler->FreePtr(TypeHandler, Icc -> TagPtrs[i]); + LocalTypeHandler = *TypeHandler; + LocalTypeHandler.ContextID = Icc ->ContextID; // As an additional parameter + LocalTypeHandler.ICCVersion = Icc ->Version; + LocalTypeHandler.FreePtr(&LocalTypeHandler, Icc -> TagPtrs[i]); } } } @@ -1571,7 +1627,7 @@ // Let the tag descriptor to decide the type base on depending on // the data. This is useful for example on parametric curves, where // curves specified by a table cannot be saved as parametric and needs - // to be revented to single v2-curves, even on v4 profiles. + // to be casted to single v2-curves, even on v4 profiles. Type = TagDescriptor ->DecideType(Version, data); } @@ -1609,9 +1665,10 @@ Icc ->TagSizes[i] = 0; Icc ->TagOffsets[i] = 0; - TypeHandler ->ContextID = Icc ->ContextID; - TypeHandler ->ICCVersion = Icc ->Version; - Icc ->TagPtrs[i] = TypeHandler ->DupPtr(TypeHandler, data, TagDescriptor ->ElemCount); + LocalTypeHandler = *TypeHandler; + LocalTypeHandler.ContextID = Icc ->ContextID; + LocalTypeHandler.ICCVersion = Icc ->Version; + Icc ->TagPtrs[i] = LocalTypeHandler.DupPtr(&LocalTypeHandler, data, TagDescriptor ->ElemCount); if (Icc ->TagPtrs[i] == NULL) { @@ -1638,6 +1695,7 @@ int i; cmsIOHANDLER* MemIO; cmsTagTypeHandler* TypeHandler = NULL; + cmsTagTypeHandler LocalTypeHandler; cmsTagDescriptor* TagDescriptor = NULL; cmsUInt32Number rc; cmsUInt32Number Offset, TagSize; @@ -1653,15 +1711,16 @@ Offset = Icc ->TagOffsets[i]; TagSize = Icc ->TagSizes[i]; - // read the data directly, don't keep copy if (data != NULL) { if (BufferSize < TagSize) - TagSize = BufferSize; + TagSize = BufferSize; if (!Icc ->IOhandler ->Seek(Icc ->IOhandler, Offset)) return 0; if (!Icc ->IOhandler ->Read(Icc ->IOhandler, data, 1, TagSize)) return 0; + + return TagSize; } return Icc ->TagSizes[i]; @@ -1675,9 +1734,11 @@ TagSize = Icc ->TagSizes[i]; if (BufferSize < TagSize) - TagSize = BufferSize; + TagSize = BufferSize; memmove(data, Icc ->TagPtrs[i], TagSize); + + return TagSize; } return Icc ->TagSizes[i]; @@ -1693,7 +1754,7 @@ if (data == NULL) { MemIO = cmsOpenIOhandlerFromNULL(cmsGetProfileContextID(hProfile)); } else{ - MemIO = cmsOpenIOhandlerFromMem(cmsGetProfileContextID(hProfile), data, BufferSize, "w"); + MemIO = cmsOpenIOhandlerFromMem(cmsGetProfileContextID(hProfile), data, BufferSize, "w"); } if (MemIO == NULL) return 0; @@ -1701,20 +1762,22 @@ TypeHandler = Icc ->TagTypeHandlers[i]; TagDescriptor = _cmsGetTagDescriptor(sig); if (TagDescriptor == NULL) { - cmsCloseIOhandler(MemIO); - return 0; + cmsCloseIOhandler(MemIO); + return 0; } + // FIXME: No handling for TypeHandler == NULL here? // Serialize - TypeHandler ->ContextID = Icc ->ContextID; - TypeHandler ->ICCVersion = Icc ->Version; + LocalTypeHandler = *TypeHandler; + LocalTypeHandler.ContextID = Icc ->ContextID; + LocalTypeHandler.ICCVersion = Icc ->Version; if (!_cmsWriteTypeBase(MemIO, TypeHandler ->Signature)) { cmsCloseIOhandler(MemIO); return 0; } - if (!TypeHandler ->WritePtr(TypeHandler, MemIO, Object, TagDescriptor ->ElemCount)) { + if (!LocalTypeHandler.WritePtr(&LocalTypeHandler, MemIO, Object, TagDescriptor ->ElemCount)) { cmsCloseIOhandler(MemIO); return 0; } @@ -1752,7 +1815,7 @@ // Using this function you can collapse several tag entries to the same block in the profile cmsBool CMSEXPORT cmsLinkTag(cmsHPROFILE hProfile, cmsTagSignature sig, cmsTagSignature dest) { - _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; + _cmsICCPROFILE* Icc = (_cmsICCPROFILE*) hProfile; int i; if (!_cmsNewTag(Icc, sig, &i)) return FALSE;
--- a/src/share/native/sun/java2d/cmm/lcms/cmsio1.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsio1.c Fri May 02 20:39:34 2014 +0100 @@ -129,7 +129,6 @@ Tag = (cmsMAT3*) cmsReadTag(hProfile, cmsSigChromaticAdaptationTag); if (Tag != NULL) { - *Dest = *Tag; return TRUE; } @@ -193,7 +192,8 @@ if (GrayTRC == NULL) return NULL; Lut = cmsPipelineAlloc(ContextID, 1, 3); - if (Lut == NULL) return NULL; + if (Lut == NULL) + goto Error; if (cmsGetPCS(hProfile) == cmsSigLabData) { @@ -204,28 +204,35 @@ EmptyTab = cmsBuildTabulatedToneCurve16(ContextID, 2, Zero); - if (EmptyTab == NULL) { - - cmsPipelineFree(Lut); - return NULL; - } + if (EmptyTab == NULL) + goto Error; LabCurves[0] = GrayTRC; LabCurves[1] = EmptyTab; LabCurves[2] = EmptyTab; - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, OneToThreeInputMatrix, NULL)); - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, LabCurves)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, OneToThreeInputMatrix, NULL)) || + !cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, LabCurves))) { + cmsFreeToneCurve(EmptyTab); + goto Error; + } cmsFreeToneCurve(EmptyTab); } else { - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &GrayTRC)); - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, GrayInputMatrix, NULL)); + + if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &GrayTRC)) || + !cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, GrayInputMatrix, NULL))) + goto Error; } return Lut; + +Error: + cmsFreeToneCurve(GrayTRC); + cmsPipelineFree(Lut); + return NULL; } // RGB Matrix shaper @@ -259,49 +266,31 @@ Lut = cmsPipelineAlloc(ContextID, 3, 3); if (Lut != NULL) { - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, Shapes)); - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Mat, NULL)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, Shapes)) || + !cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Mat, NULL))) + goto Error; // Note that it is certainly possible a single profile would have a LUT based // tag for output working in lab and a matrix-shaper for the fallback cases. // This is not allowed by the spec, but this code is tolerant to those cases if (cmsGetPCS(hProfile) == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocXYZ2Lab(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocXYZ2Lab(ContextID))) + goto Error; } } return Lut; + +Error: + cmsPipelineFree(Lut); + return NULL; } // Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded -/*static -cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) -{ - cmsContext ContextID = cmsGetProfileContextID(hProfile); - cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); - cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile); - - if (Lut == NULL) return NULL; - - // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding, - // and since the formatter has already accomodated to 0..1.0, we should undo this change - if ( spc == cmsSigLabData) - { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); - } - else - if (spc == cmsSigXYZData) - { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); - } - - return Lut; -} -*/ static cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) { @@ -316,23 +305,31 @@ // these need to be normalized into the appropriate ranges (Lab = 100,0,0, XYZ=1.0,1.0,1.0) if ( spc == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID))) + goto Error; } else if (spc == cmsSigXYZData) { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID))) + goto Error; } if ( PCS == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID))) + goto Error; } else if( PCS == cmsSigXYZData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID))) + goto Error; } return Lut; + +Error: + cmsPipelineFree(Lut); + return NULL; } @@ -359,8 +356,11 @@ return NULL; } - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(nc, TRUE)); - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(nc, TRUE)) || + !cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID))) { + cmsPipelineFree(Lut); + return NULL; + } return Lut; } @@ -395,12 +395,18 @@ return Lut; // If the input is Lab, add also a conversion at the begin - if (cmsGetColorSpace(hProfile) == cmsSigLabData) - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)); + if (cmsGetColorSpace(hProfile) == cmsSigLabData && + !cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID))) + goto Error; // Add a matrix for conversion V2 to V4 Lab PCS - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID))) + goto Error; + return Lut; +Error: + cmsPipelineFree(Lut); + return NULL; } // Lut was not found, try to create a matrix-shaper @@ -445,21 +451,27 @@ if (cmsGetPCS(hProfile) == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1, 3, PickLstarMatrix, NULL)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1, 3, PickLstarMatrix, NULL))) + goto Error; } else { - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1, 3, PickYMatrix, NULL)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1, 3, PickYMatrix, NULL))) + goto Error; } - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &RevGrayTRC)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &RevGrayTRC))) + goto Error; + cmsFreeToneCurve(RevGrayTRC); - return Lut; + +Error: + cmsFreeToneCurve(RevGrayTRC); + cmsPipelineFree(Lut); + return NULL; } - - static cmsPipeline* BuildRGBOutputMatrixShaper(cmsHPROFILE hProfile) { @@ -506,15 +518,21 @@ // This is not allowed by the spec, but this code is tolerant to those cases if (cmsGetPCS(hProfile) == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLab2XYZ(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLab2XYZ(ContextID))) + goto Error; } - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Inv, NULL)); - cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, InvShapes)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Inv, NULL)) || + !cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, InvShapes))) + goto Error; } cmsFreeToneCurveTriple(InvShapes); return Lut; +Error: + cmsFreeToneCurveTriple(InvShapes); + cmsPipelineFree(Lut); + return NULL; } @@ -540,30 +558,6 @@ // Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded -/*static -cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) -{ - cmsContext ContextID = cmsGetProfileContextID(hProfile); - cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); - cmsColorSpaceSignature PCS = cmsGetPCS(hProfile); - - if (Lut == NULL) return NULL; - - // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding, - // and since the formatter has already accomodated to 0..1.0, we should undo this change - if ( PCS == cmsSigLabData) - { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); - } - else - if (PCS == cmsSigXYZData) - { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); - } - - return Lut; -}*/ - static cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) { @@ -578,25 +572,33 @@ // and since the formatter has already accomodated to 0..1.0, we should undo this change if ( PCS == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID))) + goto Error; } else if (PCS == cmsSigXYZData) { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID))) + goto Error; } // the output can be Lab or XYZ, in which case normalisation is needed on the end of the pipeline if ( dataSpace == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID))) + goto Error; } - else if ( dataSpace == cmsSigXYZData) + else if (dataSpace == cmsSigXYZData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID))) + goto Error; } return Lut; + +Error: + cmsPipelineFree(Lut); + return NULL; } // Create an output MPE LUT from agiven profile. Version mismatches are handled here @@ -636,30 +638,35 @@ // Now it is time for a controversial stuff. I found that for 3D LUTS using // Lab used as indexer space, trilinear interpolation should be used if (cmsGetPCS(hProfile) == cmsSigLabData) - ChangeInterpolationToTrilinear(Lut); + ChangeInterpolationToTrilinear(Lut); // We need to adjust data only for Lab and Lut16 type if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData) return Lut; // Add a matrix for conversion V4 to V2 Lab PCS - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID))) + goto Error; // If the output is Lab, add also a conversion at the end if (cmsGetColorSpace(hProfile) == cmsSigLabData) - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID))) + goto Error; return Lut; +Error: + cmsPipelineFree(Lut); + return NULL; } // Lut not found, try to create a matrix-shaper // Check if this is a grayscale profile. - if (cmsGetColorSpace(hProfile) == cmsSigGrayData) { + if (cmsGetColorSpace(hProfile) == cmsSigGrayData) { - // if so, build appropiate conversion tables. - // The tables are the PCS iluminant, scaled across GrayTRC - return BuildGrayOutputPipeline(hProfile); + // if so, build appropiate conversion tables. + // The tables are the PCS iluminant, scaled across GrayTRC + return BuildGrayOutputPipeline(hProfile); } // Not gray, create a normal matrix-shaper, which only operates in XYZ space @@ -681,25 +688,32 @@ if (spc == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID))) + goto Error; } else if (spc == cmsSigXYZData) { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID))) + goto Error; } if (PCS == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID))) + goto Error; } else if (PCS == cmsSigXYZData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID))) + goto Error; } - return Lut; + return Lut; +Error: + cmsPipelineFree(Lut); + return NULL; } // This one includes abstract profiles as well. Matrix-shaper cannot be obtained on that device class. The @@ -721,15 +735,21 @@ if (nc == NULL) return NULL; Lut = cmsPipelineAlloc(ContextID, 0, 0); - if (Lut == NULL) { - cmsFreeNamedColorList(nc); - return NULL; - } + if (Lut == NULL) + goto Error; + + if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(nc, FALSE))) + goto Error; - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(nc, FALSE)); if (cmsGetColorSpace(hProfile) == cmsSigLabData) - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)); + if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID))) + goto Error; + return Lut; +Error: + cmsPipelineFree(Lut); + cmsFreeNamedColorList(nc); + return NULL; } if (cmsIsTag(hProfile, tagFloat)) { // Float tag takes precedence @@ -760,10 +780,10 @@ Lut = cmsPipelineDup(Lut); if (Lut == NULL) return NULL; - // Now it is time for a controversial stuff. I found that for 3D LUTS using - // Lab used as indexer space, trilinear interpolation should be used + // Now it is time for a controversial stuff. I found that for 3D LUTS using + // Lab used as indexer space, trilinear interpolation should be used if (cmsGetColorSpace(hProfile) == cmsSigLabData) - ChangeInterpolationToTrilinear(Lut); + ChangeInterpolationToTrilinear(Lut); // After reading it, we have info about the original type OriginalType = _cmsGetTagTrueType(hProfile, tag16); @@ -774,16 +794,20 @@ // Here it is possible to get Lab on both sides if (cmsGetPCS(hProfile) == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)); + if(!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID))) + goto Error2; } if (cmsGetColorSpace(hProfile) == cmsSigLabData) { - cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)); + if(!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID))) + goto Error2; } return Lut; - +Error2: + cmsPipelineFree(Lut); + return NULL; } // ---------------------------------------------------------------------------------------------------------------
--- a/src/share/native/sun/java2d/cmm/lcms/cmslut.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmslut.c Fri May 02 20:39:34 2014 +0100 @@ -264,10 +264,10 @@ if (NewElem ->TheCurves != NULL) { for (i=0; i < NewElem ->nCurves; i++) { if (NewElem ->TheCurves[i]) - cmsFreeToneCurve(Data ->TheCurves[i]); + cmsFreeToneCurve(NewElem ->TheCurves[i]); } } - _cmsFree(mpe ->ContextID, Data ->TheCurves); + _cmsFree(mpe ->ContextID, NewElem ->TheCurves); _cmsFree(mpe ->ContextID, NewElem); return NULL; } @@ -392,6 +392,8 @@ void MatrixElemTypeFree(cmsStage* mpe) { _cmsStageMatrixData* Data = (_cmsStageMatrixData*) mpe ->Data; + if (Data == NULL) + return; if (Data ->Double) _cmsFree(mpe ->ContextID, Data ->Double); @@ -526,10 +528,15 @@ if (Data ->Tab.T) { - if (Data ->HasFloatValues) + if (Data ->HasFloatValues) { NewElem ->Tab.TFloat = (cmsFloat32Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.TFloat, Data ->nEntries * sizeof (cmsFloat32Number)); - else + if (NewElem ->Tab.TFloat == NULL) + goto Error; + } else { NewElem ->Tab.T = (cmsUInt16Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.T, Data ->nEntries * sizeof (cmsUInt16Number)); + if (NewElem ->Tab.TFloat == NULL) + goto Error; + } } NewElem ->Params = _cmsComputeInterpParamsEx(mpe ->ContextID, @@ -538,8 +545,14 @@ Data ->Params ->nOutputs, NewElem ->Tab.T, Data ->Params ->dwFlags); - - return (void*) NewElem; + if (NewElem->Params != NULL) + return (void*) NewElem; + Error: + if (NewElem->Tab.T) + // This works for both types + _cmsFree(mpe ->ContextID, NewElem -> Tab.T); + _cmsFree(mpe ->ContextID, NewElem); + return NULL; } @@ -636,7 +649,6 @@ for (i=0; i < MAX_INPUT_DIMENSIONS; i++) Dimensions[i] = nGridPoints; - return cmsStageAllocCLut16bitGranular(ContextID, Dimensions, inputChan, outputChan, Table); } @@ -706,15 +718,12 @@ } } - NewElem ->Params = _cmsComputeInterpParamsEx(ContextID, clutPoints, inputChan, outputChan, NewElem ->Tab.TFloat, CMS_LERP_FLAGS_FLOAT); if (NewElem ->Params == NULL) { cmsStageFree(NewMPE); return NULL; } - - return NewMPE; } @@ -772,7 +781,7 @@ int i, t, nTotalPoints, index, rest; int nInputs, nOutputs; cmsUInt32Number* nSamples; - cmsUInt16Number In[cmsMAXCHANNELS], Out[MAX_STAGE_CHANNELS]; + cmsUInt16Number In[MAX_INPUT_DIMENSIONS+1], Out[MAX_STAGE_CHANNELS]; _cmsStageCLutData* clut; if (mpe == NULL) return FALSE; @@ -785,7 +794,9 @@ nInputs = clut->Params ->nInputs; nOutputs = clut->Params ->nOutputs; - if (nInputs >= cmsMAXCHANNELS) return FALSE; + if (nInputs <= 0) return FALSE; + if (nOutputs <= 0) return FALSE; + if (nInputs > MAX_INPUT_DIMENSIONS) return FALSE; if (nOutputs >= MAX_STAGE_CHANNELS) return FALSE; nTotalPoints = CubeSize(nSamples, nInputs); @@ -832,14 +843,16 @@ int i, t, nTotalPoints, index, rest; int nInputs, nOutputs; cmsUInt32Number* nSamples; - cmsFloat32Number In[cmsMAXCHANNELS], Out[MAX_STAGE_CHANNELS]; + cmsFloat32Number In[MAX_INPUT_DIMENSIONS+1], Out[MAX_STAGE_CHANNELS]; _cmsStageCLutData* clut = (_cmsStageCLutData*) mpe->Data; nSamples = clut->Params ->nSamples; nInputs = clut->Params ->nInputs; nOutputs = clut->Params ->nOutputs; - if (nInputs >= cmsMAXCHANNELS) return FALSE; + if (nInputs <= 0) return FALSE; + if (nOutputs <= 0) return FALSE; + if (nInputs > MAX_INPUT_DIMENSIONS) return FALSE; if (nOutputs >= MAX_STAGE_CHANNELS) return FALSE; nTotalPoints = CubeSize(nSamples, nInputs); @@ -1021,7 +1034,7 @@ mpe = cmsStageAllocToneCurves(ContextID, 3, LabTable); cmsFreeToneCurveTriple(LabTable); - if (mpe == NULL) return mpe; + if (mpe == NULL) return NULL; mpe ->Implements = cmsSigLabV2toV4; return mpe; } @@ -1247,12 +1260,22 @@ NULL); if (NewMPE == NULL) return NULL; - NewMPE ->Implements = mpe ->Implements; + NewMPE ->Implements = mpe ->Implements; + + if (mpe ->DupElemPtr) { + + NewMPE ->Data = mpe ->DupElemPtr(mpe); + + if (NewMPE->Data == NULL) { - if (mpe ->DupElemPtr) - NewMPE ->Data = mpe ->DupElemPtr(mpe); - else + cmsStageFree(NewMPE); + return NULL; + } + + } else { + NewMPE ->Data = NULL; + } return NewMPE; } @@ -1465,12 +1488,12 @@ } -void CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage* mpe) +int CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage* mpe) { cmsStage* Anterior = NULL, *pt; - _cmsAssert(lut != NULL); - _cmsAssert(mpe != NULL); + if (lut == NULL || mpe == NULL) + return FALSE; switch (loc) { @@ -1494,9 +1517,11 @@ } break; default:; + return FALSE; } BlessLUT(lut); + return TRUE; } // Unlink an element and return the pointer to it @@ -1558,7 +1583,7 @@ // Concatenate two LUT into a new single one cmsBool CMSEXPORT cmsPipelineCat(cmsPipeline* l1, const cmsPipeline* l2) { - cmsStage* mpe, *NewMPE; + cmsStage* mpe; // If both LUTS does not have elements, we need to inherit // the number of channels @@ -1573,17 +1598,12 @@ mpe = mpe ->Next) { // We have to dup each element - NewMPE = cmsStageDup(mpe); - - if (NewMPE == NULL) { - return FALSE; - } - - cmsPipelineInsertStage(l1, cmsAT_END, NewMPE); + if (!cmsPipelineInsertStage(l1, cmsAT_END, cmsStageDup(mpe))) + return FALSE; } - BlessLUT(l1); - return TRUE; + BlessLUT(l1); + return TRUE; } @@ -1713,16 +1733,11 @@ cmsFloat32Number fx[4], x[4], xd[4], fxd[4]; cmsVEC3 tmp, tmp2; cmsMAT3 Jacobian; - cmsFloat64Number LastResult[4]; - // Only 3->3 and 4->3 are supported if (lut ->InputChannels != 3 && lut ->InputChannels != 4) return FALSE; if (lut ->OutputChannels != 3) return FALSE; - // Mark result of -1 - LastResult[0] = LastResult[1] = LastResult[2] = -1.0f; - // Take the hint as starting point if specified if (Hint == NULL) {
--- a/src/share/native/sun/java2d/cmm/lcms/cmsmd5.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsmd5.c Fri May 02 20:39:34 2014 +0100 @@ -338,7 +338,7 @@ Error: // Free resources as something went wrong - if (MD5 != NULL) _cmsFree(ContextID, MD5); + // "MD5" cannot be other than NULL here, so no need to free it if (Mem != NULL) _cmsFree(ContextID, Mem); memmove(Icc, &Keep, sizeof(_cmsICCPROFILE)); return FALSE;
--- a/src/share/native/sun/java2d/cmm/lcms/cmsnamed.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsnamed.c Fri May 02 20:39:34 2014 +0100 @@ -359,9 +359,9 @@ if (Best == -1) Best = 0; - v = mlu ->Entries + Best; + v = mlu ->Entries + Best; - if (UsedLanguageCode != NULL) *UsedLanguageCode = v ->Language; + if (UsedLanguageCode != NULL) *UsedLanguageCode = v ->Language; if (UsedCountryCode != NULL) *UsedCountryCode = v ->Country; if (len != NULL) *len = v ->Len; @@ -475,6 +475,35 @@ } + +// Get the number of translations in the MLU object +cmsUInt32Number CMSEXPORT cmsMLUtranslationsCount(const cmsMLU* mlu) +{ + if (mlu == NULL) return 0; + return mlu->UsedEntries; +} + +// Get the language and country codes for a specific MLU index +cmsBool CMSEXPORT cmsMLUtranslationsCodes(const cmsMLU* mlu, + cmsUInt32Number idx, + char LanguageCode[3], + char CountryCode[3]) +{ + _cmsMLUentry *entry; + + if (mlu == NULL) return FALSE; + + if (idx >= (cmsUInt32Number) mlu->UsedEntries) return FALSE; + + entry = &mlu->Entries[idx]; + + *(cmsUInt16Number *)LanguageCode = _cmsAdjustEndianess16(entry->Language); + *(cmsUInt16Number *)CountryCode = _cmsAdjustEndianess16(entry->Country); + + return TRUE; +} + + // Named color lists -------------------------------------------------------------------------------------------- // Grow the list to keep at least NumElements @@ -517,9 +546,9 @@ while (v -> Allocated < n) GrowNamedColorList(v); - strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix) - 1); - strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix) - 1); - v->Prefix[sizeof(v ->Prefix) - 1] = v->Suffix[sizeof(v ->Suffix) - 1] = 0; + strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1); + strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix)-1); + v->Prefix[32] = v->Suffix[32] = 0; v -> ColorantCount = ColorantCount; @@ -529,8 +558,9 @@ // Free a list void CMSEXPORT cmsFreeNamedColorList(cmsNAMEDCOLORLIST* v) { + if (v == NULL) return; if (v ->List) _cmsFree(v ->ContextID, v ->List); - if (v) _cmsFree(v ->ContextID, v); + _cmsFree(v ->ContextID, v); } cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v) @@ -576,11 +606,8 @@ if (Name != NULL) { - strncpy(NamedColorList ->List[NamedColorList ->nColors].Name, Name, - sizeof(NamedColorList ->List[NamedColorList ->nColors].Name) - 1); - - NamedColorList ->List[NamedColorList ->nColors]. - Name[sizeof(NamedColorList ->List[NamedColorList ->nColors].Name) - 1] = 0; + strncpy(NamedColorList ->List[NamedColorList ->nColors].Name, Name, cmsMAX_PATH-1); + NamedColorList ->List[NamedColorList ->nColors].Name[cmsMAX_PATH-1] = 0; } else @@ -891,7 +918,6 @@ { _cmsDICT* old_dict = (_cmsDICT*) hDict; cmsHANDLE hNew; - _cmsDICT* new_dict; cmsDICTentry *entry; _cmsAssert(old_dict != NULL); @@ -899,8 +925,6 @@ hNew = cmsDictAlloc(old_dict ->ContextID); if (hNew == NULL) return NULL; - new_dict = (_cmsDICT*) hNew; - // Walk the list freeing all nodes entry = old_dict ->head; while (entry != NULL) {
--- a/src/share/native/sun/java2d/cmm/lcms/cmsopt.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsopt.c Fri May 02 20:39:34 2014 +0100 @@ -27,6 +27,7 @@ // However, the following notice accompanied the original version of this // file: // + //--------------------------------------------------------------------------------- // // Little Color Management System @@ -81,10 +82,6 @@ int nInputs; int nOutputs; - // Since there is no limitation of the output number of channels, this buffer holding the connexion CLUT-shaper - // has to be dynamically allocated. This is not the case of first step shaper-CLUT, which is limited to max inputs - cmsUInt16Number* StageDEF; - _cmsInterpFn16 EvalCurveIn16[MAX_INPUT_DIMENSIONS]; // The maximum number of input channels is known in advance cmsInterpParams* ParamsCurveIn16[MAX_INPUT_DIMENSIONS]; @@ -202,8 +199,6 @@ { cmsBool AnyOpt = FALSE, Opt; - AnyOpt = FALSE; - do { Opt = FALSE; @@ -253,6 +248,7 @@ { Prelin16Data* p16 = (Prelin16Data*) D; cmsUInt16Number StageABC[MAX_INPUT_DIMENSIONS]; + cmsUInt16Number StageDEF[cmsMAXCHANNELS]; int i; for (i=0; i < p16 ->nInputs; i++) { @@ -260,11 +256,11 @@ p16 ->EvalCurveIn16[i](&Input[i], &StageABC[i], p16 ->ParamsCurveIn16[i]); } - p16 ->EvalCLUT(StageABC, p16 ->StageDEF, p16 ->CLUTparams); + p16 ->EvalCLUT(StageABC, StageDEF, p16 ->CLUTparams); for (i=0; i < p16 ->nOutputs; i++) { - p16 ->EvalCurveOut16[i](&p16->StageDEF[i], &Output[i], p16 ->ParamsCurveOut16[i]); + p16 ->EvalCurveOut16[i](&StageDEF[i], &Output[i], p16 ->ParamsCurveOut16[i]); } } @@ -274,7 +270,6 @@ { Prelin16Data* p16 = (Prelin16Data*) ptr; - _cmsFree(ContextID, p16 ->StageDEF); _cmsFree(ContextID, p16 ->EvalCurveOut16); _cmsFree(ContextID, p16 ->ParamsCurveOut16); @@ -289,7 +284,6 @@ if (Duped == NULL) return NULL; - Duped ->StageDEF = _cmsCalloc(ContextID, p16 ->nOutputs, sizeof(cmsUInt16Number)); Duped ->EvalCurveOut16 = _cmsDupMem(ContextID, p16 ->EvalCurveOut16, p16 ->nOutputs * sizeof(_cmsInterpFn16)); Duped ->ParamsCurveOut16 = _cmsDupMem(ContextID, p16 ->ParamsCurveOut16, p16 ->nOutputs * sizeof(cmsInterpParams* )); @@ -328,7 +322,6 @@ p16 ->EvalCLUT = ColorMap ->Interpolation.Lerp16; - p16 -> StageDEF = _cmsCalloc(ContextID, p16 ->nOutputs, sizeof(cmsUInt16Number)); p16 -> EvalCurveOut16 = (_cmsInterpFn16*) _cmsCalloc(ContextID, nOutputs, sizeof(_cmsInterpFn16)); p16 -> ParamsCurveOut16 = (cmsInterpParams**) _cmsCalloc(ContextID, nOutputs, sizeof(cmsInterpParams* )); @@ -413,7 +406,7 @@ int i, index; if (CLUT -> Type != cmsSigCLutElemType) { - cmsSignalError(CLUT->ContextID, cmsERROR_INTERNAL, "(internal) Attempt to PatchLUT on non-lut MPE"); + cmsSignalError(CLUT->ContextID, cmsERROR_INTERNAL, "(internal) Attempt to PatchLUT on non-lut stage"); return FALSE; } @@ -548,6 +541,10 @@ for (i=0; i < nOuts; i++) { cmsToneCurve* InversePostLin = cmsReverseToneCurve(Curves[i]); + if (InversePostLin == NULL) { + WhiteOut[i] = 0; + continue; + } WhiteOut[i] = cmsEvalToneCurve16(InversePostLin, WhitePointOut[i]); cmsFreeToneCurve(InversePostLin); } @@ -575,8 +572,8 @@ static cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags) { - cmsPipeline* Src; - cmsPipeline* Dest; + cmsPipeline* Src = NULL; + cmsPipeline* Dest = NULL; cmsStage* mpe; cmsStage* CLUT; cmsStage *KeepPreLin = NULL, *KeepPostLin = NULL; @@ -589,7 +586,6 @@ cmsToneCurve** DataSetOut; Prelin16Data* p16; - // This is a loosy optimization! does not apply in floating-point cases if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE; @@ -603,10 +599,10 @@ Src = *Lut; - // Named color pipelines cannot be optimized either - for (mpe = cmsPipelineGetPtrToFirstStage(Src); - mpe != NULL; - mpe = cmsStageNext(mpe)) { + // Named color pipelines cannot be optimized either + for (mpe = cmsPipelineGetPtrToFirstStage(Src); + mpe != NULL; + mpe = cmsStageNext(mpe)) { if (cmsStageType(mpe) == cmsSigNamedColorElemType) return FALSE; } @@ -628,7 +624,8 @@ // All seems ok, proceed. NewPreLin = cmsStageDup(PreLin); - cmsPipelineInsertStage(Dest, cmsAT_BEGIN, NewPreLin); + if(!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, NewPreLin)) + goto Error; // Remove prelinearization. Since we have duplicated the curve // in destination LUT, the sampling shoud be applied after this stage. @@ -642,7 +639,9 @@ if (CLUT == NULL) return FALSE; // Add the CLUT to the destination LUT - cmsPipelineInsertStage(Dest, cmsAT_END, CLUT); + if (!cmsPipelineInsertStage(Dest, cmsAT_END, CLUT)) { + goto Error; + } // Postlinearization tables are kept unless indicated by flags if (*dwFlags & cmsFLAGS_CLUT_POST_LINEARIZATION) { @@ -658,7 +657,8 @@ // All seems ok, proceed. NewPostLin = cmsStageDup(PostLin); - cmsPipelineInsertStage(Dest, cmsAT_END, NewPostLin); + if (!cmsPipelineInsertStage(Dest, cmsAT_END, NewPostLin)) + goto Error; // In destination LUT, the sampling shoud be applied after this stage. cmsPipelineUnlinkStage(Src, cmsAT_END, &KeepPostLin); @@ -669,10 +669,18 @@ // Now its time to do the sampling. We have to ignore pre/post linearization // The source LUT whithout pre/post curves is passed as parameter. if (!cmsStageSampleCLut16bit(CLUT, XFormSampler16, (void*) Src, 0)) { - +Error: // Ops, something went wrong, Restore stages - if (KeepPreLin != NULL) cmsPipelineInsertStage(Src, cmsAT_BEGIN, KeepPreLin); - if (KeepPostLin != NULL) cmsPipelineInsertStage(Src, cmsAT_END, KeepPostLin); + if (KeepPreLin != NULL) { + if (!cmsPipelineInsertStage(Src, cmsAT_BEGIN, KeepPreLin)) { + _cmsAssert(0); // This never happens + } + } + if (KeepPostLin != NULL) { + if (!cmsPipelineInsertStage(Src, cmsAT_END, KeepPostLin)) { + _cmsAssert(0); // This never happens + } + } cmsPipelineFree(Dest); return FALSE; } @@ -699,12 +707,11 @@ else { p16 = PrelinOpt16alloc(Dest ->ContextID, - DataCLUT ->Params, - Dest ->InputChannels, - DataSetIn, - Dest ->OutputChannels, - DataSetOut); - + DataCLUT ->Params, + Dest ->InputChannels, + DataSetIn, + Dest ->OutputChannels, + DataSetOut); _cmsPipelineSetOptimizationParameters(Dest, PrelinEval16, (void*) p16, PrelinOpt16free, Prelin16dup); } @@ -1058,7 +1065,8 @@ LutPlusCurves = cmsPipelineDup(OriginalLut); if (LutPlusCurves == NULL) goto Error; - cmsPipelineInsertStage(LutPlusCurves, cmsAT_BEGIN, cmsStageAllocToneCurves(OriginalLut ->ContextID, OriginalLut ->InputChannels, TransReverse)); + if (!cmsPipelineInsertStage(LutPlusCurves, cmsAT_BEGIN, cmsStageAllocToneCurves(OriginalLut ->ContextID, OriginalLut ->InputChannels, TransReverse))) + goto Error; // Create the result LUT OptimizedLUT = cmsPipelineAlloc(OriginalLut ->ContextID, OriginalLut ->InputChannels, OriginalLut ->OutputChannels); @@ -1067,13 +1075,15 @@ OptimizedPrelinMpe = cmsStageAllocToneCurves(OriginalLut ->ContextID, OriginalLut ->InputChannels, Trans); // Create and insert the curves at the beginning - cmsPipelineInsertStage(OptimizedLUT, cmsAT_BEGIN, OptimizedPrelinMpe); + if (!cmsPipelineInsertStage(OptimizedLUT, cmsAT_BEGIN, OptimizedPrelinMpe)) + goto Error; // Allocate the CLUT for result OptimizedCLUTmpe = cmsStageAllocCLut16bit(OriginalLut ->ContextID, nGridPoints, OriginalLut ->InputChannels, OriginalLut ->OutputChannels, NULL); // Add the CLUT to the destination LUT - cmsPipelineInsertStage(OptimizedLUT, cmsAT_END, OptimizedCLUTmpe); + if (!cmsPipelineInsertStage(OptimizedLUT, cmsAT_END, OptimizedCLUTmpe)) + goto Error; // Resample the LUT if (!cmsStageSampleCLut16bit(OptimizedCLUTmpe, XFormSampler16, (void*) LutPlusCurves, 0)) goto Error; @@ -1201,13 +1211,14 @@ for (i=0; i < nCurves; i++) { c16->Curves[i] = _cmsCalloc(ContextID, nElements, sizeof(cmsUInt16Number)); + if (c16->Curves[i] == NULL) { + for (j=0; j < i; j++) { _cmsFree(ContextID, c16->Curves[j]); } _cmsFree(ContextID, c16->Curves); _cmsFree(ContextID, c16); - return NULL; } @@ -1336,7 +1347,8 @@ // Maybe the curves are linear at the end if (!AllCurvesAreLinear(ObtainedCurves)) { - cmsPipelineInsertStage(Dest, cmsAT_BEGIN, ObtainedCurves); + if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, ObtainedCurves)) + goto Error; // If the curves are to be applied in 8 bits, we can save memory if (_cmsFormatterIs8bit(*InputFormat)) { @@ -1344,6 +1356,7 @@ _cmsStageToneCurvesData* Data = (_cmsStageToneCurvesData*) ObtainedCurves ->Data; Curves16Data* c16 = CurvesAlloc(Dest ->ContextID, Data ->nCurves, 256, Data ->TheCurves); + if (c16 == NULL) goto Error; *dwFlags |= cmsFLAGS_NOCACHE; _cmsPipelineSetOptimizationParameters(Dest, FastEvaluateCurves8, c16, CurvesFree, CurvesDup); @@ -1353,6 +1366,7 @@ _cmsStageToneCurvesData* Data = (_cmsStageToneCurvesData*) cmsStageData(ObtainedCurves); Curves16Data* c16 = CurvesAlloc(Dest ->ContextID, Data ->nCurves, 65536, Data ->TheCurves); + if (c16 == NULL) goto Error; *dwFlags |= cmsFLAGS_NOCACHE; _cmsPipelineSetOptimizationParameters(Dest, FastEvaluateCurves16, c16, CurvesFree, CurvesDup); } @@ -1362,7 +1376,8 @@ // LUT optimizes to nothing. Set the identity LUT cmsStageFree(ObtainedCurves); - cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageAllocIdentity(Dest ->ContextID, Src ->InputChannels)); + if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageAllocIdentity(Dest ->ContextID, Src ->InputChannels))) + goto Error; *dwFlags |= cmsFLAGS_NOCACHE; _cmsPipelineSetOptimizationParameters(Dest, FastIdentity16, (void*) Dest, NULL, NULL); @@ -1592,10 +1607,14 @@ if (!Dest) return FALSE; // Assamble the new LUT - cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageDup(Curve1)); + if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageDup(Curve1))) + goto Error; + if (!IdentityMat) - cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageAllocMatrix(Dest ->ContextID, 3, 3, (const cmsFloat64Number*) &res, Data2 ->Offset)); - cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageDup(Curve2)); + if (!cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageAllocMatrix(Dest ->ContextID, 3, 3, (const cmsFloat64Number*) &res, Data2 ->Offset))) + goto Error; + if (!cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageDup(Curve2))) + goto Error; // If identity on matrix, we can further optimize the curves, so call the join curves routine if (IdentityMat) { @@ -1617,6 +1636,10 @@ cmsPipelineFree(Src); *Lut = Dest; return TRUE; +Error: + // Leave Src unchanged + cmsPipelineFree(Dest); + return FALSE; } @@ -1646,7 +1669,7 @@ static _cmsOptimizationCollection* OptimizationCollection = DefaultOptimization; // Register new ways to optimize -cmsBool _cmsRegisterOptimizationPlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterOptimizationPlugin(cmsContext id, cmsPluginBase* Data) { cmsPluginOptimization* Plugin = (cmsPluginOptimization*) Data; _cmsOptimizationCollection* fl; @@ -1660,7 +1683,7 @@ // Optimizer callback is required if (Plugin ->OptimizePtr == NULL) return FALSE; - fl = (_cmsOptimizationCollection*) _cmsPluginMalloc(sizeof(_cmsOptimizationCollection)); + fl = (_cmsOptimizationCollection*) _cmsPluginMalloc(id, sizeof(_cmsOptimizationCollection)); if (fl == NULL) return FALSE; // Copy the parameters
--- a/src/share/native/sun/java2d/cmm/lcms/cmspack.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmspack.c Fri May 02 20:39:34 2014 +0100 @@ -317,6 +317,23 @@ } static +cmsUInt8Number* Unroll3BytesSkip1SwapSwapFirst(register _cmsTRANSFORM* info, + register cmsUInt16Number wIn[], + register cmsUInt8Number* accum, + register cmsUInt32Number Stride) +{ + wIn[2] = FROM_8_TO_16(*accum); accum++; // B + wIn[1] = FROM_8_TO_16(*accum); accum++; // G + wIn[0] = FROM_8_TO_16(*accum); accum++; // R + accum++; // A + + return accum; + + cmsUNUSED_PARAMETER(info); + cmsUNUSED_PARAMETER(Stride); +} + +static cmsUInt8Number* Unroll3BytesSkip1SwapFirst(register _cmsTRANSFORM* info, register cmsUInt16Number wIn[], register cmsUInt8Number* accum, @@ -2901,6 +2918,9 @@ { CHANNELS_SH(3)|EXTRA_SH(1)|BYTES_SH(1)|DOSWAP_SH(1), ANYSPACE, Unroll3BytesSkip1Swap}, { CHANNELS_SH(3)|EXTRA_SH(1)|BYTES_SH(1)|SWAPFIRST_SH(1), ANYSPACE, Unroll3BytesSkip1SwapFirst}, + { CHANNELS_SH(3)|EXTRA_SH(1)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1), + ANYSPACE, Unroll3BytesSkip1SwapSwapFirst}, + { CHANNELS_SH(4)|BYTES_SH(1), ANYSPACE, Unroll4Bytes}, { CHANNELS_SH(4)|BYTES_SH(1)|FLAVOR_SH(1), ANYSPACE, Unroll4BytesReverse}, { CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1), ANYSPACE, Unroll4BytesSwapFirst}, @@ -3166,7 +3186,7 @@ // Formatters management -cmsBool _cmsRegisterFormattersPlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterFormattersPlugin(cmsContext id, cmsPluginBase* Data) { cmsPluginFormatters* Plugin = (cmsPluginFormatters*) Data; cmsFormattersFactoryList* fl ; @@ -3178,7 +3198,7 @@ return TRUE; } - fl = (cmsFormattersFactoryList*) _cmsPluginMalloc(sizeof(cmsFormattersFactoryList)); + fl = (cmsFormattersFactoryList*) _cmsPluginMalloc(id, sizeof(cmsFormattersFactoryList)); if (fl == NULL) return FALSE; fl ->Factory = Plugin ->FormattersFactory;
--- a/src/share/native/sun/java2d/cmm/lcms/cmspcs.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmspcs.c Fri May 02 20:39:34 2014 +0100 @@ -898,9 +898,11 @@ { switch (ColorSpace) { + case cmsSigMCH1Data: case cmsSig1colorData: case cmsSigGrayData: return 1; + case cmsSigMCH2Data: case cmsSig2colorData: return 2; case cmsSigXYZData: @@ -912,10 +914,12 @@ case cmsSigHsvData: case cmsSigHlsData: case cmsSigCmyData: + case cmsSigMCH3Data: case cmsSig3colorData: return 3; case cmsSigLuvKData: case cmsSigCmykData: + case cmsSigMCH4Data: case cmsSig4colorData: return 4; case cmsSigMCH5Data:
--- a/src/share/native/sun/java2d/cmm/lcms/cmsplugin.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsplugin.c Fri May 02 20:39:34 2014 +0100 @@ -125,10 +125,14 @@ pOut[0] = pIn[7]; #else - _cmsAssert(Result != NULL); +# ifdef CMS_DONT_USE_INT64 + (*Result)[0] = QWord[0]; + (*Result)[1] = QWord[1]; +# else *Result = *QWord; +# endif #endif } @@ -543,10 +547,10 @@ static _cmsSubAllocator* PluginPool = NULL; // Specialized malloc for plug-ins, that is freed upon exit. -void* _cmsPluginMalloc(cmsUInt32Number size) +void* _cmsPluginMalloc(cmsContext id, cmsUInt32Number size) { if (PluginPool == NULL) - PluginPool = _cmsCreateSubAlloc(0, 4*1024); + PluginPool = _cmsCreateSubAlloc(id, 4*1024); return _cmsSubAlloc(PluginPool, size); } @@ -555,6 +559,11 @@ // Main plug-in dispatcher cmsBool CMSEXPORT cmsPlugin(void* Plug_in) { + return cmsPluginTHR(NULL, Plug_in); +} + +cmsBool CMSEXPORT cmsPluginTHR(cmsContext id, void* Plug_in) +{ cmsPluginBase* Plugin; for (Plugin = (cmsPluginBase*) Plug_in; @@ -583,35 +592,35 @@ break; case cmsPluginTagTypeSig: - if (!_cmsRegisterTagTypePlugin(Plugin)) return FALSE; + if (!_cmsRegisterTagTypePlugin(id, Plugin)) return FALSE; break; case cmsPluginTagSig: - if (!_cmsRegisterTagPlugin(Plugin)) return FALSE; + if (!_cmsRegisterTagPlugin(id, Plugin)) return FALSE; break; case cmsPluginFormattersSig: - if (!_cmsRegisterFormattersPlugin(Plugin)) return FALSE; + if (!_cmsRegisterFormattersPlugin(id, Plugin)) return FALSE; break; case cmsPluginRenderingIntentSig: - if (!_cmsRegisterRenderingIntentPlugin(Plugin)) return FALSE; + if (!_cmsRegisterRenderingIntentPlugin(id, Plugin)) return FALSE; break; case cmsPluginParametricCurveSig: - if (!_cmsRegisterParametricCurvesPlugin(Plugin)) return FALSE; + if (!_cmsRegisterParametricCurvesPlugin(id, Plugin)) return FALSE; break; case cmsPluginMultiProcessElementSig: - if (!_cmsRegisterMultiProcessElementPlugin(Plugin)) return FALSE; + if (!_cmsRegisterMultiProcessElementPlugin(id, Plugin)) return FALSE; break; case cmsPluginOptimizationSig: - if (!_cmsRegisterOptimizationPlugin(Plugin)) return FALSE; + if (!_cmsRegisterOptimizationPlugin(id, Plugin)) return FALSE; break; case cmsPluginTransformSig: - if (!_cmsRegisterTransformPlugin(Plugin)) return FALSE; + if (!_cmsRegisterTransformPlugin(id, Plugin)) return FALSE; break; default: @@ -630,14 +639,14 @@ { _cmsRegisterMemHandlerPlugin(NULL); _cmsRegisterInterpPlugin(NULL); - _cmsRegisterTagTypePlugin(NULL); - _cmsRegisterTagPlugin(NULL); - _cmsRegisterFormattersPlugin(NULL); - _cmsRegisterRenderingIntentPlugin(NULL); - _cmsRegisterParametricCurvesPlugin(NULL); - _cmsRegisterMultiProcessElementPlugin(NULL); - _cmsRegisterOptimizationPlugin(NULL); - _cmsRegisterTransformPlugin(NULL); + _cmsRegisterTagTypePlugin(NULL, NULL); + _cmsRegisterTagPlugin(NULL, NULL); + _cmsRegisterFormattersPlugin(NULL, NULL); + _cmsRegisterRenderingIntentPlugin(NULL, NULL); + _cmsRegisterParametricCurvesPlugin(NULL, NULL); + _cmsRegisterMultiProcessElementPlugin(NULL, NULL); + _cmsRegisterOptimizationPlugin(NULL, NULL); + _cmsRegisterTransformPlugin(NULL, NULL); if (PluginPool != NULL) _cmsSubAllocDestroy(PluginPool);
--- a/src/share/native/sun/java2d/cmm/lcms/cmsps2.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsps2.c Fri May 02 20:39:34 2014 +0100 @@ -806,7 +806,6 @@ mpe = Pipeline ->Elements; - switch (cmsStageInputChannels(mpe)) { case 3: @@ -838,8 +837,6 @@ mpe = mpe ->Next; } - - if (cmsStageType(mpe) == cmsSigCLutElemType) { _cmsIOPrintf(m, "/Table "); @@ -854,7 +851,6 @@ _cmsIOPrintf(m, " >>\n"); _cmsIOPrintf(m, "]\n"); - return 1; } @@ -950,6 +946,7 @@ rc = EmitCIEBasedDEF(m, DeviceLink, Intent, &BlackPointAdaptedToD50); cmsPipelineFree(DeviceLink); + if (rc == 0) return 0; } break;
--- a/src/share/native/sun/java2d/cmm/lcms/cmssamp.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmssamp.c Fri May 02 20:39:34 2014 +0100 @@ -56,6 +56,8 @@ #include "lcms2_internal.h" +#define cmsmin(a, b) (((a) < (b)) ? (a) : (b)) +#define cmsmax(a, b) (((a) > (b)) ? (a) : (b)) // This file contains routines for resampling and LUT optimization, black point detection // and black preservation. @@ -67,13 +69,13 @@ static cmsHTRANSFORM CreateRoundtripXForm(cmsHPROFILE hProfile, cmsUInt32Number nIntent) { - cmsHPROFILE hLab = cmsCreateLab4Profile(NULL); + cmsContext ContextID = cmsGetProfileContextID(hProfile); + cmsHPROFILE hLab = cmsCreateLab4ProfileTHR(ContextID, NULL); cmsHTRANSFORM xform; cmsBool BPC[4] = { FALSE, FALSE, FALSE, FALSE }; cmsFloat64Number States[4] = { 1.0, 1.0, 1.0, 1.0 }; cmsHPROFILE hProfiles[4]; cmsUInt32Number Intents[4]; - cmsContext ContextID = cmsGetProfileContextID(hProfile); hProfiles[0] = hLab; hProfiles[1] = hProfile; hProfiles[2] = hProfile; hProfiles[3] = hLab; Intents[0] = INTENT_RELATIVE_COLORIMETRIC; Intents[1] = nIntent; Intents[2] = INTENT_RELATIVE_COLORIMETRIC; Intents[3] = INTENT_RELATIVE_COLORIMETRIC; @@ -141,8 +143,8 @@ cmsCloseProfile(hLab); if (xform == NULL) { + // Something went wrong. Get rid of open resources and return zero as black - BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; return FALSE; } @@ -173,7 +175,6 @@ // Lab (0, 0, 0) -> [Perceptual] Profile -> CMYK -> [Rel. colorimetric] Profile -> Lab static cmsBool BlackPointUsingPerceptualBlack(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile) - { cmsHTRANSFORM hRoundTrip; cmsCIELab LabIn, LabOut; @@ -218,17 +219,27 @@ // involves to turn BP to neutral and to use only L component. cmsBool CMSEXPORT cmsDetectBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags) { + cmsProfileClassSignature devClass; - // Zero for black point - if (cmsGetDeviceClass(hProfile) == cmsSigLinkClass) { + // Make sure the device class is adequate + devClass = cmsGetDeviceClass(hProfile); + if (devClass == cmsSigLinkClass || + devClass == cmsSigAbstractClass || + devClass == cmsSigNamedColorClass) { + BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; + return FALSE; + } - BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; - return FALSE; + // Make sure intent is adequate + if (Intent != INTENT_PERCEPTUAL && + Intent != INTENT_RELATIVE_COLORIMETRIC && + Intent != INTENT_SATURATION) { + BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; + return FALSE; } // v4 + perceptual & saturation intents does have its own black point, and it is // well specified enough to use it. Black point tag is deprecated in V4. - if ((cmsGetEncodedICCversion(hProfile) >= 0x4000000) && (Intent == INTENT_PERCEPTUAL || Intent == INTENT_SATURATION)) { @@ -303,7 +314,7 @@ { double sum_x = 0, sum_x2 = 0, sum_x3 = 0, sum_x4 = 0; double sum_y = 0, sum_yx = 0, sum_yx2 = 0; - double disc; + double d, a, b, c; int i; cmsMAT3 m; cmsVEC3 v, res; @@ -333,14 +344,32 @@ if (!_cmsMAT3solve(&res, &m, &v)) return 0; - // y = t x2 + u x + c - // x = ( - u + Sqrt( u^2 - 4 t c ) ) / ( 2 t ) - disc = res.n[1]*res.n[1] - 4.0 * res.n[0] * res.n[2]; - if (disc < 0) return -1; + + a = res.n[2]; + b = res.n[1]; + c = res.n[0]; + + if (fabs(a) < 1.0E-10) { + + return cmsmin(0, cmsmax(50, -c/b )); + } + else { - return ( -1.0 * res.n[1] + sqrt( disc )) / (2.0 * res.n[0]); + d = b*b - 4.0 * a * c; + if (d <= 0) { + return 0; + } + else { + + double rt = (-b + sqrt(d)) / (2.0 * a); + + return cmsmax(0, cmsmin(50, rt)); + } + } + } +/* static cmsBool IsMonotonic(int n, const cmsFloat64Number Table[]) { @@ -361,6 +390,7 @@ return TRUE; } +*/ // Calculates the black point of a destination profile. // This algorithm comes from the Adobe paper disclosing its black point compensation method. @@ -369,21 +399,30 @@ cmsColorSpaceSignature ColorSpace; cmsHTRANSFORM hRoundTrip = NULL; cmsCIELab InitialLab, destLab, Lab; - + cmsFloat64Number inRamp[256], outRamp[256]; cmsFloat64Number MinL, MaxL; - cmsBool NearlyStraightMidRange = FALSE; - cmsFloat64Number L; - cmsFloat64Number x[101], y[101]; - cmsFloat64Number lo, hi, NonMonoMin; - int n, l, i, NonMonoIndx; + cmsBool NearlyStraightMidrange = TRUE; + cmsFloat64Number yRamp[256]; + cmsFloat64Number x[256], y[256]; + cmsFloat64Number lo, hi; + int n, l; + cmsProfileClassSignature devClass; + // Make sure the device class is adequate + devClass = cmsGetDeviceClass(hProfile); + if (devClass == cmsSigLinkClass || + devClass == cmsSigAbstractClass || + devClass == cmsSigNamedColorClass) { + BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; + return FALSE; + } // Make sure intent is adequate if (Intent != INTENT_PERCEPTUAL && Intent != INTENT_RELATIVE_COLORIMETRIC && Intent != INTENT_SATURATION) { - BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; - return FALSE; + BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; + return FALSE; } @@ -415,10 +454,8 @@ return cmsDetectBlackPoint(BlackPoint, hProfile, Intent, dwFlags); } - // It is one of the valid cases!, presto chargo hocus pocus, go for the Adobe magic + // It is one of the valid cases!, use Adobe algorithm - // Step 1 - // ====== // Set a first guess, that should work on good profiles. if (Intent == INTENT_RELATIVE_COLORIMETRIC) { @@ -449,71 +486,68 @@ hRoundTrip = CreateRoundtripXForm(hProfile, Intent); if (hRoundTrip == NULL) return FALSE; - // Calculate Min L* - Lab = InitialLab; - Lab.L = 0; - cmsDoTransform(hRoundTrip, &Lab, &destLab, 1); - MinL = destLab.L; + // Compute ramps - // Calculate Max L* - Lab = InitialLab; - Lab.L = 100; - cmsDoTransform(hRoundTrip, &Lab, &destLab, 1); - MaxL = destLab.L; + for (l=0; l < 256; l++) { - // Step 3 - // ====== - - // check if quadratic estimation needs to be done. - if (Intent == INTENT_RELATIVE_COLORIMETRIC) { + Lab.L = (cmsFloat64Number) (l * 100.0) / 255.0; + Lab.a = cmsmin(50, cmsmax(-50, InitialLab.a)); + Lab.b = cmsmin(50, cmsmax(-50, InitialLab.b)); - // Conceptually, this code tests how close the source l and converted L are to one another in the mid-range - // of the values. If the converted ramp of L values is close enough to a straight line y=x, then InitialLab - // is good enough to be the DestinationBlackPoint, - NearlyStraightMidRange = TRUE; - - for (l=0; l <= 100; l++) { + cmsDoTransform(hRoundTrip, &Lab, &destLab, 1); - Lab.L = l; - Lab.a = InitialLab.a; - Lab.b = InitialLab.b; - - cmsDoTransform(hRoundTrip, &Lab, &destLab, 1); - - L = destLab.L; - - // Check the mid range in 20% after MinL - if (L > (MinL + 0.2 * (MaxL - MinL))) { + inRamp[l] = Lab.L; + outRamp[l] = destLab.L; + } - // Is close enough? - if (fabs(L - l) > 4.0) { + // Make monotonic + for (l = 254; l > 0; --l) { + outRamp[l] = cmsmin(outRamp[l], outRamp[l+1]); + } - // Too far away, profile is buggy! - NearlyStraightMidRange = FALSE; - break; - } - } - } - } - else { - // Check is always performed for perceptual and saturation intents - NearlyStraightMidRange = FALSE; + // Check + if (! (outRamp[0] < outRamp[255])) { + + cmsDeleteTransform(hRoundTrip); + BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; + return FALSE; } - // If no furter checking is needed, we are done - if (NearlyStraightMidRange) { + // Test for mid range straight (only on relative colorimetric) + + NearlyStraightMidrange = TRUE; + MinL = outRamp[0]; MaxL = outRamp[255]; + if (Intent == INTENT_RELATIVE_COLORIMETRIC) { + + for (l=0; l < 256; l++) { - cmsLab2XYZ(NULL, BlackPoint, &InitialLab); - cmsDeleteTransform(hRoundTrip); - return TRUE; + if (! ((inRamp[l] <= MinL + 0.2 * (MaxL - MinL) ) || + (fabs(inRamp[l] - outRamp[l]) < 4.0 ))) + NearlyStraightMidrange = FALSE; + } + + // If the mid range is straight (as determined above) then the + // DestinationBlackPoint shall be the same as initialLab. + // Otherwise, the DestinationBlackPoint shall be determined + // using curve fitting. + + if (NearlyStraightMidrange) { + + cmsLab2XYZ(NULL, BlackPoint, &InitialLab); + cmsDeleteTransform(hRoundTrip); + return TRUE; + } } - // The round-trip curve normally looks like a nearly constant section at the black point, + + // curve fitting: The round-trip curve normally looks like a nearly constant section at the black point, // with a corner and a nearly straight line to the white point. - // STEP 4 - // ======= + for (l=0; l < 256; l++) { + + yRamp[l] = (outRamp[l] - MinL) / (MaxL - MinL); + } // find the black point using the least squares error quadratic curve fitting @@ -528,62 +562,32 @@ hi = 0.25; } - // Capture points for the fitting. + // Capture shadow points for the fitting. n = 0; - for (l=0; l <= 100; l++) { - - cmsFloat64Number ff; + for (l=0; l < 256; l++) { - Lab.L = (cmsFloat64Number) l; - Lab.a = InitialLab.a; - Lab.b = InitialLab.b; - - cmsDoTransform(hRoundTrip, &Lab, &destLab, 1); - - ff = (destLab.L - MinL)/(MaxL - MinL); + cmsFloat64Number ff = yRamp[l]; if (ff >= lo && ff < hi) { - - x[n] = Lab.L; - y[n] = ff; + x[n] = inRamp[l]; + y[n] = yRamp[l]; n++; } - - } - - // This part is not on the Adobe paper, but I found is necessary for getting any result. - - if (IsMonotonic(n, y)) { - - // Monotonic means lower point is stil valid - cmsLab2XYZ(NULL, BlackPoint, &InitialLab); - cmsDeleteTransform(hRoundTrip); - return TRUE; - } - - // No suitable points, regret and use safer algorithm - if (n == 0) { - cmsDeleteTransform(hRoundTrip); - return cmsDetectBlackPoint(BlackPoint, hProfile, Intent, dwFlags); } - NonMonoMin = 100; - NonMonoIndx = 0; - for (i=0; i < n; i++) { - - if (y[i] < NonMonoMin) { - NonMonoIndx = i; - NonMonoMin = y[i]; - } + // No suitable points + if (n < 3 ) { + cmsDeleteTransform(hRoundTrip); + BlackPoint -> X = BlackPoint ->Y = BlackPoint -> Z = 0.0; + return FALSE; } - Lab.L = x[NonMonoIndx]; // fit and get the vertex of quadratic curve Lab.L = RootOfLeastSquaresFitQuadraticCurve(n, x, y); - if (Lab.L < 0.0 || Lab.L > 50.0) { // clip to zero L* if the vertex is negative + if (Lab.L < 0.0) { // clip to zero L* if the vertex is negative Lab.L = 0; }
--- a/src/share/native/sun/java2d/cmm/lcms/cmstypes.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmstypes.c Fri May 02 20:39:34 2014 +0100 @@ -91,7 +91,7 @@ // Register a new type handler. This routine is shared between normal types and MPE static -cmsBool RegisterTypesPlugin(cmsPluginBase* Data, _cmsTagTypeLinkedList* LinkedList, cmsUInt32Number DefaultListCount) +cmsBool RegisterTypesPlugin(cmsContext id, cmsPluginBase* Data, _cmsTagTypeLinkedList* LinkedList, cmsUInt32Number DefaultListCount) { cmsPluginTagType* Plugin = (cmsPluginTagType*) Data; _cmsTagTypeLinkedList *pt, *Anterior = NULL; @@ -118,7 +118,7 @@ } // Registering happens in plug-in memory pool - pt = (_cmsTagTypeLinkedList*) _cmsPluginMalloc(sizeof(_cmsTagTypeLinkedList)); + pt = (_cmsTagTypeLinkedList*) _cmsPluginMalloc(id, sizeof(_cmsTagTypeLinkedList)); if (pt == NULL) return FALSE; pt ->Handler = Plugin ->Handler; @@ -208,10 +208,10 @@ cmsUInt32Number *ElementOffsets = NULL, *ElementSizes = NULL; // Let's take the offsets to each element - ElementOffsets = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number *)); + ElementOffsets = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number)); if (ElementOffsets == NULL) goto Error; - ElementSizes = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number *)); + ElementSizes = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number)); if (ElementSizes == NULL) goto Error; for (i=0; i < Count; i++) { @@ -257,10 +257,10 @@ cmsUInt32Number *ElementOffsets = NULL, *ElementSizes = NULL; // Create table - ElementOffsets = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number *)); + ElementOffsets = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number)); if (ElementOffsets == NULL) goto Error; - ElementSizes = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number *)); + ElementSizes = (cmsUInt32Number *) _cmsCalloc(io ->ContextID, Count, sizeof(cmsUInt32Number)); if (ElementSizes == NULL) goto Error; // Keep starting position of curve offsets @@ -456,6 +456,7 @@ void* Type_Chromaticity_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cmsUInt32Number n) { return _cmsDupMem(self ->ContextID, Ptr, sizeof(cmsCIExyYTRIPLE)); + cmsUNUSED_PARAMETER(n); } @@ -1106,8 +1107,6 @@ { cmsUInt32Number Count; cmsToneCurve* NewGamma; - cmsUInt16Number Linear[2] = { 0, 0xffff }; - *nItems = 0; if (!_cmsReadUInt32Number(io, &Count)) return NULL; @@ -1115,11 +1114,14 @@ switch (Count) { case 0: // Linear. - - NewGamma = cmsBuildTabulatedToneCurve16(self ->ContextID, 2, Linear); - if (!NewGamma) return NULL; - *nItems = 1; - return NewGamma; + { + cmsFloat64Number SingleGamma = 1.0; + + NewGamma = cmsBuildParametricToneCurve(self ->ContextID, 1, &SingleGamma); + if (!NewGamma) return NULL; + *nItems = 1; + return NewGamma; + } case 1: // Specified as the exponent of gamma function { @@ -1210,6 +1212,7 @@ if (ICCVersion < 4.0) return cmsSigCurveType; if (Curve ->nSegments != 1) return cmsSigCurveType; // Only 1-segment curves can be saved as parametric if (Curve ->Segments[0].Type < 0) return cmsSigCurveType; // Only non-inverted curves + if (Curve ->Segments[0].Type > 5) return cmsSigCurveType; // Only ICC parametric curves return cmsSigParametricCurveType; } @@ -1386,6 +1389,9 @@ { cmsICCMeasurementConditions mc; + + memset(&mc, 0, sizeof(mc)); + if (!_cmsReadUInt32Number(io, &mc.Observer)) return NULL; if (!_cmsReadXYZNumber(io, &mc.Backing)) return NULL; if (!_cmsReadUInt32Number(io, &mc.Geometry)) return NULL; @@ -1640,7 +1646,6 @@ static cmsBool Read8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut, int nChannels) { - cmsStage* mpe; cmsUInt8Number* Temp = NULL; int i, j; cmsToneCurve* Tables[cmsMAXCHANNELS]; @@ -1669,11 +1674,8 @@ _cmsFree(ContextID, Temp); Temp = NULL; - - mpe = cmsStageAllocToneCurves(ContextID, nChannels, Tables); - if (mpe == NULL) goto Error; - - cmsPipelineInsertStage(lut, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, nChannels, Tables))) + goto Error; for (i=0; i < nChannels; i++) cmsFreeToneCurve(Tables[i]); @@ -1701,21 +1703,30 @@ if (Tables) { - if (Tables ->TheCurves[i]->nEntries != 256) { - cmsSignalError(ContextID, cmsERROR_RANGE, "LUT8 needs 256 entries on prelinearization"); - return FALSE; + // Usual case of identity curves + if ((Tables ->TheCurves[i]->nEntries == 2) && + (Tables->TheCurves[i]->Table16[0] == 0) && + (Tables->TheCurves[i]->Table16[1] == 65535)) { + + for (j=0; j < 256; j++) { + if (!_cmsWriteUInt8Number(io, (cmsUInt8Number) j)) return FALSE; + } } - - } - - for (j=0; j < 256; j++) { - - if (Tables != NULL) - val = (cmsUInt8Number) FROM_16_TO_8(Tables->TheCurves[i]->Table16[j]); else - val = (cmsUInt8Number) j; - - if (!_cmsWriteUInt8Number(io, val)) return FALSE; + if (Tables ->TheCurves[i]->nEntries != 256) { + cmsSignalError(ContextID, cmsERROR_RANGE, "LUT8 needs 256 entries on prelinearization"); + return FALSE; + } + else + for (j=0; j < 256; j++) { + + if (Tables != NULL) + val = (cmsUInt8Number) FROM_16_TO_8(Tables->TheCurves[i]->Table16[j]); + else + val = (cmsUInt8Number) j; + + if (!_cmsWriteUInt8Number(io, val)) return FALSE; + } } } return TRUE; @@ -1724,7 +1735,7 @@ // Check overflow static -size_t uipow(cmsUInt32Number n, cmsUInt32Number a, cmsUInt32Number b) +cmsUInt32Number uipow(cmsUInt32Number n, cmsUInt32Number a, cmsUInt32Number b) { cmsUInt32Number rv = 1, rc; @@ -1736,13 +1747,13 @@ rv *= a; // Check for overflow - if (rv > UINT_MAX / a) return (size_t) -1; + if (rv > UINT_MAX / a) return (cmsUInt32Number) -1; } rc = rv * n; - if (rv != rc / n) return (size_t) -1; + if (rv != rc / n) return (cmsUInt32Number) -1; return rc; } @@ -1757,7 +1768,6 @@ cmsUInt8Number InputChannels, OutputChannels, CLUTpoints; cmsUInt8Number* Temp = NULL; cmsPipeline* NewLUT = NULL; - cmsStage *mpemat, *mpeclut; cmsUInt32Number nTabSize, i; cmsFloat64Number Matrix[3*3]; @@ -1796,9 +1806,8 @@ // Only operates if not identity... if ((InputChannels == 3) && !_cmsMAT3isIdentity((cmsMAT3*) Matrix)) { - mpemat = cmsStageAllocMatrix(self ->ContextID, 3, 3, Matrix, NULL); - if (mpemat == NULL) goto Error; - cmsPipelineInsertStage(NewLUT, cmsAT_BEGIN, mpemat); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_BEGIN, cmsStageAllocMatrix(self ->ContextID, 3, 3, Matrix, NULL))) + goto Error; } // Get input tables @@ -1806,13 +1815,10 @@ // Get 3D CLUT. Check the overflow.... nTabSize = uipow(OutputChannels, CLUTpoints, InputChannels); - if (nTabSize == (size_t) -1) goto Error; + if (nTabSize == (cmsUInt32Number) -1) goto Error; if (nTabSize > 0) { cmsUInt16Number *PtrW, *T; - cmsUInt32Number Tsize; - - Tsize = (cmsUInt32Number) nTabSize * sizeof(cmsUInt16Number); PtrW = T = (cmsUInt16Number*) _cmsCalloc(self ->ContextID, nTabSize, sizeof(cmsUInt16Number)); if (T == NULL) goto Error; @@ -1829,10 +1835,8 @@ _cmsFree(self ->ContextID, Temp); Temp = NULL; - - mpeclut = cmsStageAllocCLut16bit(self ->ContextID, CLUTpoints, InputChannels, OutputChannels, T); - if (mpeclut == NULL) goto Error; - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpeclut); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, cmsStageAllocCLut16bit(self ->ContextID, CLUTpoints, InputChannels, OutputChannels, T))) + goto Error; _cmsFree(self ->ContextID, T); } @@ -1934,7 +1938,7 @@ if (!Write8bitTables(self ->ContextID, io, NewLUT ->InputChannels, PreMPE)) return FALSE; nTabSize = uipow(NewLUT->OutputChannels, clutPoints, NewLUT ->InputChannels); - if (nTabSize == (size_t) -1) return FALSE; + if (nTabSize == (cmsUInt32Number) -1) return FALSE; if (nTabSize > 0) { // The 3D CLUT. @@ -1983,7 +1987,6 @@ static cmsBool Read16bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut, int nChannels, int nEntries) { - cmsStage* mpe; int i; cmsToneCurve* Tables[cmsMAXCHANNELS]; @@ -2007,10 +2010,8 @@ // Add the table (which may certainly be an identity, but this is up to the optimizer, not the reading code) - mpe = cmsStageAllocToneCurves(ContextID, nChannels, Tables); - if (mpe == NULL) goto Error; - - cmsPipelineInsertStage(lut, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, nChannels, Tables))) + goto Error; for (i=0; i < nChannels; i++) cmsFreeToneCurve(Tables[i]); @@ -2031,7 +2032,9 @@ int j; cmsUInt32Number i; cmsUInt16Number val; - int nEntries = 256; + int nEntries; + + _cmsAssert(Tables != NULL); nEntries = Tables->TheCurves[0]->nEntries; @@ -2039,11 +2042,7 @@ for (j=0; j < nEntries; j++) { - if (Tables != NULL) - val = Tables->TheCurves[i]->Table16[j]; - else - val = _cmsQuantizeVal(j, nEntries); - + val = Tables->TheCurves[i]->Table16[j]; if (!_cmsWriteUInt16Number(io, val)) return FALSE; } } @@ -2057,7 +2056,6 @@ { cmsUInt8Number InputChannels, OutputChannels, CLUTpoints; cmsPipeline* NewLUT = NULL; - cmsStage *mpemat, *mpeclut; cmsUInt32Number nTabSize; cmsFloat64Number Matrix[3*3]; cmsUInt16Number InputEntries, OutputEntries; @@ -2094,9 +2092,8 @@ // Only operates on 3 channels if ((InputChannels == 3) && !_cmsMAT3isIdentity((cmsMAT3*) Matrix)) { - mpemat = cmsStageAllocMatrix(self ->ContextID, 3, 3, Matrix, NULL); - if (mpemat == NULL) goto Error; - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpemat); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, cmsStageAllocMatrix(self ->ContextID, 3, 3, Matrix, NULL))) + goto Error; } if (!_cmsReadUInt16Number(io, &InputEntries)) goto Error; @@ -2110,7 +2107,7 @@ // Get 3D CLUT nTabSize = uipow(OutputChannels, CLUTpoints, InputChannels); - if (nTabSize == (size_t) -1) goto Error; + if (nTabSize == (cmsUInt32Number) -1) goto Error; if (nTabSize > 0) { cmsUInt16Number *T; @@ -2123,13 +2120,10 @@ goto Error; } - mpeclut = cmsStageAllocCLut16bit(self ->ContextID, CLUTpoints, InputChannels, OutputChannels, T); - if (mpeclut == NULL) { - _cmsFree(self ->ContextID, T); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, cmsStageAllocCLut16bit(self ->ContextID, CLUTpoints, InputChannels, OutputChannels, T))) { + _cmsFree(self ->ContextID, T); goto Error; } - - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpeclut); _cmsFree(self ->ContextID, T); } @@ -2159,7 +2153,7 @@ _cmsStageToneCurvesData* PreMPE = NULL, *PostMPE = NULL; _cmsStageMatrixData* MatMPE = NULL; _cmsStageCLutData* clut = NULL; - int InputChannels, OutputChannels, clutPoints; + int i, InputChannels, OutputChannels, clutPoints; // Disassemble the LUT into components. mpe = NewLUT -> Elements; @@ -2234,13 +2228,13 @@ if (PreMPE != NULL) { if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) PreMPE ->TheCurves[0]->nEntries)) return FALSE; } else { - if (!_cmsWriteUInt16Number(io, 0)) return FALSE; + if (!_cmsWriteUInt16Number(io, 2)) return FALSE; } if (PostMPE != NULL) { if (!_cmsWriteUInt16Number(io, (cmsUInt16Number) PostMPE ->TheCurves[0]->nEntries)) return FALSE; } else { - if (!_cmsWriteUInt16Number(io, 0)) return FALSE; + if (!_cmsWriteUInt16Number(io, 2)) return FALSE; } @@ -2249,9 +2243,16 @@ if (PreMPE != NULL) { if (!Write16bitTables(self ->ContextID, io, PreMPE)) return FALSE; } + else { + for (i=0; i < InputChannels; i++) { + + if (!_cmsWriteUInt16Number(io, 0)) return FALSE; + if (!_cmsWriteUInt16Number(io, 0xffff)) return FALSE; + } + } nTabSize = uipow(OutputChannels, clutPoints, InputChannels); - if (nTabSize == (size_t) -1) return FALSE; + if (nTabSize == (cmsUInt32Number) -1) return FALSE; if (nTabSize > 0) { // The 3D CLUT. if (clut != NULL) { @@ -2263,7 +2264,13 @@ if (PostMPE != NULL) { if (!Write16bitTables(self ->ContextID, io, PostMPE)) return FALSE; } - + else { + for (i=0; i < OutputChannels; i++) { + + if (!_cmsWriteUInt16Number(io, 0)) return FALSE; + if (!_cmsWriteUInt16Number(io, 0xffff)) return FALSE; + } + } return TRUE; @@ -2479,7 +2486,6 @@ cmsUInt32Number offsetM; // Offset to first "M" curve cmsUInt32Number offsetC; // Offset to CLUT cmsUInt32Number offsetA; // Offset to first "A" curve - cmsStage* mpe; cmsPipeline* NewLUT = NULL; @@ -2501,37 +2507,35 @@ if (NewLUT == NULL) return NULL; if (offsetA!= 0) { - mpe = ReadSetOfCurves(self, io, BaseOffset + offsetA, inputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadSetOfCurves(self, io, BaseOffset + offsetA, inputChan))) + goto Error; } if (offsetC != 0) { - mpe = ReadCLUT(self, io, BaseOffset + offsetC, inputChan, outputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadCLUT(self, io, BaseOffset + offsetC, inputChan, outputChan))) + goto Error; } if (offsetM != 0) { - mpe = ReadSetOfCurves(self, io, BaseOffset + offsetM, outputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadSetOfCurves(self, io, BaseOffset + offsetM, outputChan))) + goto Error; } if (offsetMat != 0) { - mpe = ReadMatrix(self, io, BaseOffset + offsetMat); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadMatrix(self, io, BaseOffset + offsetMat))) + goto Error; } if (offsetB != 0) { - mpe = ReadSetOfCurves(self, io, BaseOffset + offsetB, outputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadSetOfCurves(self, io, BaseOffset + offsetB, outputChan))) + goto Error; } *nItems = 1; return NewLUT; +Error: + cmsPipelineFree(NewLUT); + return NULL; cmsUNUSED_PARAMETER(SizeOfTag); } @@ -2798,7 +2802,6 @@ cmsUInt32Number offsetM; // Offset to first "M" curve cmsUInt32Number offsetC; // Offset to CLUT cmsUInt32Number offsetA; // Offset to first "A" curve - cmsStage* mpe; cmsPipeline* NewLUT = NULL; @@ -2821,37 +2824,35 @@ if (NewLUT == NULL) return NULL; if (offsetB != 0) { - mpe = ReadSetOfCurves(self, io, BaseOffset + offsetB, inputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadSetOfCurves(self, io, BaseOffset + offsetB, inputChan))) + goto Error; } if (offsetMat != 0) { - mpe = ReadMatrix(self, io, BaseOffset + offsetMat); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadMatrix(self, io, BaseOffset + offsetMat))) + goto Error; } if (offsetM != 0) { - mpe = ReadSetOfCurves(self, io, BaseOffset + offsetM, inputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadSetOfCurves(self, io, BaseOffset + offsetM, inputChan))) + goto Error; } if (offsetC != 0) { - mpe = ReadCLUT(self, io, BaseOffset + offsetC, inputChan, outputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadCLUT(self, io, BaseOffset + offsetC, inputChan, outputChan))) + goto Error; } if (offsetA!= 0) { - mpe = ReadSetOfCurves(self, io, BaseOffset + offsetA, outputChan); - if (mpe == NULL) { cmsPipelineFree(NewLUT); return NULL; } - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, ReadSetOfCurves(self, io, BaseOffset + offsetA, outputChan))) + goto Error; } *nItems = 1; return NewLUT; +Error: + cmsPipelineFree(NewLUT); + return NULL; cmsUNUSED_PARAMETER(SizeOfTag); } @@ -3287,7 +3288,7 @@ SizeOfTag -= sizeof(cmsUInt32Number); if (!_cmsReadUInt64Number(io, &sec ->attributes)) goto Error; - if (SizeOfTag < sizeof(cmsUInt32Number)) goto Error; + if (SizeOfTag < sizeof(cmsUInt64Number)) goto Error; SizeOfTag -= sizeof(cmsUInt64Number); if (!_cmsReadUInt32Number(io, (cmsUInt32Number *)&sec ->technology)) goto Error; @@ -4292,6 +4293,9 @@ if (!_cmsReadUInt16Number(io, &InputChans)) return NULL; if (!_cmsReadUInt16Number(io, &OutputChans)) return NULL; + if (InputChans == 0) goto Error; + if (OutputChans == 0) goto Error; + if (io ->Read(io, Dimensions8, sizeof(cmsUInt8Number), 16) != 16) goto Error; @@ -4381,7 +4385,6 @@ { cmsStageSignature ElementSig; cmsTagTypeHandler* TypeHandler; - cmsStage *mpe = NULL; cmsUInt32Number nItems; cmsPipeline *NewLUT = (cmsPipeline *) Cargo; @@ -4409,11 +4412,8 @@ if (TypeHandler ->ReadPtr != NULL) { // This is a real element which should be read and processed - mpe = (cmsStage*) TypeHandler ->ReadPtr(self, io, &nItems, SizeOfTag); - if (mpe == NULL) return FALSE; - - // All seems ok, insert element - cmsPipelineInsertStage(NewLUT, cmsAT_END, mpe); + if (!cmsPipelineInsertStage(NewLUT, cmsAT_END, (cmsStage*) TypeHandler ->ReadPtr(self, io, &nItems, SizeOfTag))) + return FALSE; } return TRUE; @@ -4479,10 +4479,10 @@ outputChan = cmsPipelineOutputChannels(Lut); ElemCount = cmsPipelineStageCount(Lut); - ElementOffsets = (cmsUInt32Number *) _cmsCalloc(self ->ContextID, ElemCount, sizeof(cmsUInt32Number *)); + ElementOffsets = (cmsUInt32Number *) _cmsCalloc(self ->ContextID, ElemCount, sizeof(cmsUInt32Number)); if (ElementOffsets == NULL) goto Error; - ElementSizes = (cmsUInt32Number *) _cmsCalloc(self ->ContextID, ElemCount, sizeof(cmsUInt32Number *)); + ElementSizes = (cmsUInt32Number *) _cmsCalloc(self ->ContextID, ElemCount, sizeof(cmsUInt32Number)); if (ElementSizes == NULL) goto Error; // Write the head @@ -4825,10 +4825,10 @@ static cmsBool AllocElem(cmsContext ContextID, _cmsDICelem* e, cmsUInt32Number Count) { - e->Offsets = (cmsUInt32Number *) _cmsCalloc(ContextID, Count, sizeof(cmsUInt32Number *)); + e->Offsets = (cmsUInt32Number *) _cmsCalloc(ContextID, Count, sizeof(cmsUInt32Number)); if (e->Offsets == NULL) return FALSE; - e->Sizes = (cmsUInt32Number *) _cmsCalloc(ContextID, Count, sizeof(cmsUInt32Number *)); + e->Sizes = (cmsUInt32Number *) _cmsCalloc(ContextID, Count, sizeof(cmsUInt32Number)); if (e->Sizes == NULL) { _cmsFree(ContextID, e -> Offsets); @@ -4844,7 +4844,7 @@ void FreeElem(_cmsDICelem* e) { if (e ->Offsets != NULL) _cmsFree(e -> ContextID, e -> Offsets); - if (e ->Sizes != NULL) _cmsFree(e -> ContextID, e ->Sizes); + if (e ->Sizes != NULL) _cmsFree(e -> ContextID, e -> Sizes); e->Offsets = e ->Sizes = NULL; } @@ -5084,7 +5084,7 @@ if (!_cmsReadUInt32Number(io, &Count)) return NULL; SizeOfTag -= sizeof(cmsUInt32Number); - // Get rec lenghth + // Get rec length if (!_cmsReadUInt32Number(io, &Length)) return NULL; SizeOfTag -= sizeof(cmsUInt32Number); @@ -5118,14 +5118,22 @@ if (!ReadOneMLUC(self, io, &a.DisplayValue, i, &DisplayValueMLU)) goto Error; } + if (NameWCS == NULL || ValueWCS == NULL) { + + cmsSignalError(self->ContextID, cmsERROR_CORRUPTION_DETECTED, "Bad dictionary Name/Value"); + rc = FALSE; + } + else { + rc = cmsDictAddEntry(hDict, NameWCS, ValueWCS, DisplayNameMLU, DisplayValueMLU); + } if (NameWCS != NULL) _cmsFree(self ->ContextID, NameWCS); if (ValueWCS != NULL) _cmsFree(self ->ContextID, ValueWCS); if (DisplayNameMLU != NULL) cmsMLUfree(DisplayNameMLU); if (DisplayValueMLU != NULL) cmsMLUfree(DisplayValueMLU); - if (!rc) return FALSE; + if (!rc) goto Error; } FreeArray(&a); @@ -5277,14 +5285,14 @@ #define DEFAULT_TAG_TYPE_COUNT (sizeof(SupportedTagTypes) / sizeof(_cmsTagTypeLinkedList)) // Both kind of plug-ins share same structure -cmsBool _cmsRegisterTagTypePlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterTagTypePlugin(cmsContext id, cmsPluginBase* Data) { - return RegisterTypesPlugin(Data, SupportedTagTypes, DEFAULT_TAG_TYPE_COUNT); + return RegisterTypesPlugin(id, Data, SupportedTagTypes, DEFAULT_TAG_TYPE_COUNT); } -cmsBool _cmsRegisterMultiProcessElementPlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterMultiProcessElementPlugin(cmsContext id, cmsPluginBase* Data) { - return RegisterTypesPlugin(Data, SupportedMPEtypes, DEFAULT_MPE_TYPE_COUNT); + return RegisterTypesPlugin(id, Data, SupportedMPEtypes, DEFAULT_MPE_TYPE_COUNT); } @@ -5391,7 +5399,9 @@ { cmsSigScreeningTag, { 1, 1, { cmsSigScreeningType}, NULL }, &SupportedTags[59]}, { cmsSigVcgtTag, { 1, 1, { cmsSigVcgtType}, NULL }, &SupportedTags[60]}, { cmsSigMetaTag, { 1, 1, { cmsSigDictType}, NULL }, &SupportedTags[61]}, - { cmsSigProfileSequenceIdTag, { 1, 1, { cmsSigProfileSequenceIdType}, NULL}, NULL} + { cmsSigProfileSequenceIdTag, { 1, 1, { cmsSigProfileSequenceIdType}, NULL }, &SupportedTags[62]}, + { cmsSigProfileDescriptionMLTag,{ 1, 1, { cmsSigMultiLocalizedUnicodeType}, NULL}, NULL} + }; @@ -5406,7 +5416,7 @@ #define DEFAULT_TAG_COUNT (sizeof(SupportedTags) / sizeof(_cmsTagLinkedList)) -cmsBool _cmsRegisterTagPlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterTagPlugin(cmsContext id, cmsPluginBase* Data) { cmsPluginTag* Plugin = (cmsPluginTag*) Data; _cmsTagLinkedList *pt, *Anterior; @@ -5430,7 +5440,7 @@ pt = pt ->Next; } - pt = (_cmsTagLinkedList*) _cmsPluginMalloc(sizeof(_cmsTagLinkedList)); + pt = (_cmsTagLinkedList*) _cmsPluginMalloc(id, sizeof(_cmsTagLinkedList)); if (pt == NULL) return FALSE; pt ->Signature = Plugin ->Signature;
--- a/src/share/native/sun/java2d/cmm/lcms/cmsvirt.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsvirt.c Fri May 02 20:39:34 2014 +0100 @@ -208,9 +208,26 @@ if (TransferFunction) { + // Tries to minimize space. Thanks to Richard Hughes for this nice idea if (!cmsWriteTag(hICC, cmsSigRedTRCTag, (void*) TransferFunction[0])) goto Error; - if (!cmsWriteTag(hICC, cmsSigGreenTRCTag, (void*) TransferFunction[1])) goto Error; - if (!cmsWriteTag(hICC, cmsSigBlueTRCTag, (void*) TransferFunction[2])) goto Error; + + if (TransferFunction[1] == TransferFunction[0]) { + + if (!cmsLinkTag (hICC, cmsSigGreenTRCTag, cmsSigRedTRCTag)) goto Error; + + } else { + + if (!cmsWriteTag(hICC, cmsSigGreenTRCTag, (void*) TransferFunction[1])) goto Error; + } + + if (TransferFunction[2] == TransferFunction[0]) { + + if (!cmsLinkTag (hICC, cmsSigBlueTRCTag, cmsSigRedTRCTag)) goto Error; + + } else { + + if (!cmsWriteTag(hICC, cmsSigBlueTRCTag, (void*) TransferFunction[2])) goto Error; + } } if (Primaries) { @@ -303,7 +320,6 @@ { cmsHPROFILE hICC; cmsPipeline* Pipeline; - cmsStage* Lin; int nChannels; hICC = cmsCreateProfilePlaceholder(ContextID); @@ -327,10 +343,8 @@ // Copy tables to Pipeline - Lin = cmsStageAllocToneCurves(ContextID, nChannels, TransferFunctions); - if (Lin == NULL) goto Error; - - cmsPipelineInsertStage(Pipeline, cmsAT_BEGIN, Lin); + if (!cmsPipelineInsertStage(Pipeline, cmsAT_BEGIN, cmsStageAllocToneCurves(ContextID, nChannels, TransferFunctions))) + goto Error; // Create tags if (!SetTextTags(hICC, L"Linearization built-in")) goto Error; @@ -344,6 +358,7 @@ return hICC; Error: + cmsPipelineFree(Pipeline); if (hICC) cmsCloseProfile(hICC); @@ -451,9 +466,10 @@ if (!cmsStageSampleCLut16bit(CLUT, InkLimitingSampler, (void*) &Limit, 0)) goto Error; - cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, nChannels)); - cmsPipelineInsertStage(LUT, cmsAT_END, CLUT); - cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, nChannels)); + if (!cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, nChannels)) || + !cmsPipelineInsertStage(LUT, cmsAT_END, CLUT) || + !cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, nChannels))) + goto Error; // Create tags if (!SetTextTags(hICC, L"ink-limiting built-in")) goto Error; @@ -504,7 +520,8 @@ LUT = cmsPipelineAlloc(ContextID, 3, 3); if (LUT == NULL) goto Error; - cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCLut(ContextID, 3)); + if (!cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCLut(ContextID, 3))) + goto Error; if (!cmsWriteTag(hProfile, cmsSigAToB0Tag, LUT)) goto Error; cmsPipelineFree(LUT); @@ -550,7 +567,8 @@ LUT = cmsPipelineAlloc(ContextID, 3, 3); if (LUT == NULL) goto Error; - cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 3)); + if (!cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 3))) + goto Error; if (!cmsWriteTag(hProfile, cmsSigAToB0Tag, LUT)) goto Error; cmsPipelineFree(LUT); @@ -595,7 +613,8 @@ LUT = cmsPipelineAlloc(ContextID, 3, 3); if (LUT == NULL) goto Error; - cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 3)); + if (!cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, 3))) + goto Error; if (!cmsWriteTag(hProfile, cmsSigAToB0Tag, LUT)) goto Error; cmsPipelineFree(LUT); @@ -734,81 +753,83 @@ // contrast, Saturation and white point displacement cmsHPROFILE CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID, - int nLUTPoints, - cmsFloat64Number Bright, - cmsFloat64Number Contrast, - cmsFloat64Number Hue, - cmsFloat64Number Saturation, - int TempSrc, - int TempDest) + int nLUTPoints, + cmsFloat64Number Bright, + cmsFloat64Number Contrast, + cmsFloat64Number Hue, + cmsFloat64Number Saturation, + int TempSrc, + int TempDest) { - cmsHPROFILE hICC; - cmsPipeline* Pipeline; - BCHSWADJUSTS bchsw; - cmsCIExyY WhitePnt; - cmsStage* CLUT; - cmsUInt32Number Dimensions[MAX_INPUT_DIMENSIONS]; - int i; + cmsHPROFILE hICC; + cmsPipeline* Pipeline; + BCHSWADJUSTS bchsw; + cmsCIExyY WhitePnt; + cmsStage* CLUT; + cmsUInt32Number Dimensions[MAX_INPUT_DIMENSIONS]; + int i; - - bchsw.Brightness = Bright; - bchsw.Contrast = Contrast; - bchsw.Hue = Hue; - bchsw.Saturation = Saturation; + bchsw.Brightness = Bright; + bchsw.Contrast = Contrast; + bchsw.Hue = Hue; + bchsw.Saturation = Saturation; - cmsWhitePointFromTemp(&WhitePnt, TempSrc ); - cmsxyY2XYZ(&bchsw.WPsrc, &WhitePnt); + cmsWhitePointFromTemp(&WhitePnt, TempSrc ); + cmsxyY2XYZ(&bchsw.WPsrc, &WhitePnt); - cmsWhitePointFromTemp(&WhitePnt, TempDest); - cmsxyY2XYZ(&bchsw.WPdest, &WhitePnt); + cmsWhitePointFromTemp(&WhitePnt, TempDest); + cmsxyY2XYZ(&bchsw.WPdest, &WhitePnt); - hICC = cmsCreateProfilePlaceholder(ContextID); - if (!hICC) // can't allocate - return NULL; + hICC = cmsCreateProfilePlaceholder(ContextID); + if (!hICC) // can't allocate + return NULL; - cmsSetDeviceClass(hICC, cmsSigAbstractClass); - cmsSetColorSpace(hICC, cmsSigLabData); - cmsSetPCS(hICC, cmsSigLabData); + cmsSetDeviceClass(hICC, cmsSigAbstractClass); + cmsSetColorSpace(hICC, cmsSigLabData); + cmsSetPCS(hICC, cmsSigLabData); - cmsSetHeaderRenderingIntent(hICC, INTENT_PERCEPTUAL); - + cmsSetHeaderRenderingIntent(hICC, INTENT_PERCEPTUAL); - // Creates a Pipeline with 3D grid only - Pipeline = cmsPipelineAlloc(ContextID, 3, 3); - if (Pipeline == NULL) { - cmsCloseProfile(hICC); - return NULL; - } + // Creates a Pipeline with 3D grid only + Pipeline = cmsPipelineAlloc(ContextID, 3, 3); + if (Pipeline == NULL) { + cmsCloseProfile(hICC); + return NULL; + } - for (i=0; i < MAX_INPUT_DIMENSIONS; i++) Dimensions[i] = nLUTPoints; - CLUT = cmsStageAllocCLut16bitGranular(ContextID, Dimensions, 3, 3, NULL); - if (CLUT == NULL) return NULL; + for (i=0; i < MAX_INPUT_DIMENSIONS; i++) Dimensions[i] = nLUTPoints; + CLUT = cmsStageAllocCLut16bitGranular(ContextID, Dimensions, 3, 3, NULL); + if (CLUT == NULL) return NULL; - if (!cmsStageSampleCLut16bit(CLUT, bchswSampler, (void*) &bchsw, 0)) { + if (!cmsStageSampleCLut16bit(CLUT, bchswSampler, (void*) &bchsw, 0)) { + + // Shouldn't reach here + goto Error; + } - // Shouldn't reach here - cmsPipelineFree(Pipeline); - cmsCloseProfile(hICC); - return NULL; - } + if (!cmsPipelineInsertStage(Pipeline, cmsAT_END, CLUT)) { + goto Error; + } - cmsPipelineInsertStage(Pipeline, cmsAT_END, CLUT); - - // Create tags + // Create tags + if (!SetTextTags(hICC, L"BCHS built-in")) return NULL; - if (!SetTextTags(hICC, L"BCHS built-in")) return NULL; + cmsWriteTag(hICC, cmsSigMediaWhitePointTag, (void*) cmsD50_XYZ()); - cmsWriteTag(hICC, cmsSigMediaWhitePointTag, (void*) cmsD50_XYZ()); + cmsWriteTag(hICC, cmsSigAToB0Tag, (void*) Pipeline); - cmsWriteTag(hICC, cmsSigAToB0Tag, (void*) Pipeline); + // Pipeline is already on virtual profile + cmsPipelineFree(Pipeline); - // Pipeline is already on virtual profile - cmsPipelineFree(Pipeline); + // Ok, done + return hICC; - // Ok, done - return hICC; +Error: + cmsPipelineFree(Pipeline); + cmsCloseProfile(hICC); + return NULL; } @@ -856,7 +877,8 @@ PostLin = cmsStageAllocToneCurves(ContextID, 1, &EmptyTab); cmsFreeToneCurve(EmptyTab); - cmsPipelineInsertStage(LUT, cmsAT_END, PostLin); + if (!cmsPipelineInsertStage(LUT, cmsAT_END, PostLin)) + goto Error; if (!cmsWriteTag(hProfile, cmsSigBToA0Tag, (void*) LUT)) goto Error; if (!cmsWriteTag(hProfile, cmsSigMediaWhitePointTag, cmsD50_XYZ())) goto Error; @@ -999,6 +1021,7 @@ { FALSE, 0, cmsSigLut16Type, 4, { cmsSigMatrixElemType, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType}}, { FALSE, 0, cmsSigLut16Type, 3, { cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType}}, + { FALSE, 0, cmsSigLut16Type, 2, { cmsSigCurveSetElemType, cmsSigCLutElemType}}, { TRUE , 0, cmsSigLutAtoBType, 1, { cmsSigCurveSetElemType }}, { TRUE , cmsSigAToB0Tag, cmsSigLutAtoBType, 3, { cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType } }, { TRUE , cmsSigAToB0Tag, cmsSigLutAtoBType, 3, { cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType } }, @@ -1059,6 +1082,7 @@ cmsContext ContextID = cmsGetTransformContextID(hTransform); const cmsAllowedLUT* AllowedLUT; cmsTagSignature DestinationTag; + cmsProfileClassSignature deviceClass; _cmsAssert(hTransform != NULL); @@ -1080,13 +1104,15 @@ // Time to fix the Lab2/Lab4 issue. if ((xform ->EntryColorSpace == cmsSigLabData) && (Version < 4.0)) { - cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocLabV2ToV4curves(ContextID)); + if (!cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocLabV2ToV4curves(ContextID))) + goto Error; } // On the output side too if ((xform ->ExitColorSpace) == cmsSigLabData && (Version < 4.0)) { - cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocLabV4ToV2(ContextID)); + if (!cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocLabV4ToV2(ContextID))) + goto Error; } @@ -1108,8 +1134,9 @@ FrmIn = COLORSPACE_SH(ColorSpaceBitsIn) | CHANNELS_SH(ChansIn)|BYTES_SH(2); FrmOut = COLORSPACE_SH(ColorSpaceBitsOut) | CHANNELS_SH(ChansOut)|BYTES_SH(2); + deviceClass = cmsGetDeviceClass(hProfile); - if (cmsGetDeviceClass(hProfile) == cmsSigOutputClass) + if (deviceClass == cmsSigOutputClass) DestinationTag = cmsSigBToA0Tag; else DestinationTag = cmsSigAToB0Tag; @@ -1136,10 +1163,12 @@ // Put identity curves if needed if (cmsPipelineGetPtrToFirstStage(LUT) ->Type != cmsSigCurveSetElemType) - cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, ChansIn)); + if (!cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, ChansIn))) + goto Error; if (cmsPipelineGetPtrToLastStage(LUT) ->Type != cmsSigCurveSetElemType) - cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, ChansOut)); + if (!cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, ChansOut))) + goto Error; AllowedLUT = FindCombination(LUT, Version >= 4.0, DestinationTag); } @@ -1168,10 +1197,22 @@ if (!cmsWriteTag(hProfile, cmsSigColorantTableOutTag, xform->OutputColorant)) goto Error; } - if (xform ->Sequence != NULL) { + if ((deviceClass == cmsSigLinkClass) && (xform ->Sequence != NULL)) { if (!_cmsWriteProfileSequence(hProfile, xform ->Sequence)) goto Error; } + // Set the white point + if (deviceClass == cmsSigInputClass) { + if (!cmsWriteTag(hProfile, cmsSigMediaWhitePointTag, &xform ->EntryWhitePoint)) goto Error; + } + else { + if (!cmsWriteTag(hProfile, cmsSigMediaWhitePointTag, &xform ->ExitWhitePoint)) goto Error; + } + + + // Per 7.2.15 in spec 4.3 + cmsSetHeaderRenderingIntent(hProfile, xform ->RenderingIntent); + cmsPipelineFree(LUT); return hProfile;
--- a/src/share/native/sun/java2d/cmm/lcms/cmswtpnt.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmswtpnt.c Fri May 02 20:39:34 2014 +0100 @@ -30,7 +30,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2012 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -76,48 +76,48 @@ // Obtains WhitePoint from Temperature cmsBool CMSEXPORT cmsWhitePointFromTemp(cmsCIExyY* WhitePoint, cmsFloat64Number TempK) { - cmsFloat64Number x, y; - cmsFloat64Number T, T2, T3; - // cmsFloat64Number M1, M2; + cmsFloat64Number x, y; + cmsFloat64Number T, T2, T3; + // cmsFloat64Number M1, M2; - _cmsAssert(WhitePoint != NULL); + _cmsAssert(WhitePoint != NULL); - T = TempK; - T2 = T*T; // Square - T3 = T2*T; // Cube + T = TempK; + T2 = T*T; // Square + T3 = T2*T; // Cube - // For correlated color temperature (T) between 4000K and 7000K: + // For correlated color temperature (T) between 4000K and 7000K: - if (T >= 4000. && T <= 7000.) - { - x = -4.6070*(1E9/T3) + 2.9678*(1E6/T2) + 0.09911*(1E3/T) + 0.244063; - } - else - // or for correlated color temperature (T) between 7000K and 25000K: + if (T >= 4000. && T <= 7000.) + { + x = -4.6070*(1E9/T3) + 2.9678*(1E6/T2) + 0.09911*(1E3/T) + 0.244063; + } + else + // or for correlated color temperature (T) between 7000K and 25000K: - if (T > 7000.0 && T <= 25000.0) - { - x = -2.0064*(1E9/T3) + 1.9018*(1E6/T2) + 0.24748*(1E3/T) + 0.237040; - } - else { - cmsSignalError(0, cmsERROR_RANGE, "cmsWhitePointFromTemp: invalid temp"); - return FALSE; - } + if (T > 7000.0 && T <= 25000.0) + { + x = -2.0064*(1E9/T3) + 1.9018*(1E6/T2) + 0.24748*(1E3/T) + 0.237040; + } + else { + cmsSignalError(0, cmsERROR_RANGE, "cmsWhitePointFromTemp: invalid temp"); + return FALSE; + } - // Obtain y(x) + // Obtain y(x) - y = -3.000*(x*x) + 2.870*x - 0.275; + y = -3.000*(x*x) + 2.870*x - 0.275; - // wave factors (not used, but here for futures extensions) + // wave factors (not used, but here for futures extensions) - // M1 = (-1.3515 - 1.7703*x + 5.9114 *y)/(0.0241 + 0.2562*x - 0.7341*y); - // M2 = (0.0300 - 31.4424*x + 30.0717*y)/(0.0241 + 0.2562*x - 0.7341*y); + // M1 = (-1.3515 - 1.7703*x + 5.9114 *y)/(0.0241 + 0.2562*x - 0.7341*y); + // M2 = (0.0300 - 31.4424*x + 30.0717*y)/(0.0241 + 0.2562*x - 0.7341*y); - WhitePoint -> x = x; - WhitePoint -> y = y; - WhitePoint -> Y = 1.0; + WhitePoint -> x = x; + WhitePoint -> y = y; + WhitePoint -> Y = 1.0; - return TRUE; + return TRUE; } @@ -266,7 +266,7 @@ {{ 0.8951, 0.2664, -0.1614 }}, {{ -0.7502, 1.7135, 0.0367 }}, {{ 0.0389, -0.0685, 1.0296 }} - }}; + }}; if (ConeMatrix == NULL) ConeMatrix = &LamRigg;
--- a/src/share/native/sun/java2d/cmm/lcms/cmsxform.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/cmsxform.c Fri May 02 20:39:34 2014 +0100 @@ -396,7 +396,7 @@ static _cmsTransformCollection* TransformCollection = NULL; // Register new ways to transform -cmsBool _cmsRegisterTransformPlugin(cmsPluginBase* Data) +cmsBool _cmsRegisterTransformPlugin(cmsContext id, cmsPluginBase* Data) { cmsPluginTransform* Plugin = (cmsPluginTransform*) Data; _cmsTransformCollection* fl; @@ -412,7 +412,7 @@ if (Plugin ->Factory == NULL) return FALSE; - fl = (_cmsTransformCollection*) _cmsPluginMalloc(sizeof(_cmsTransformCollection)); + fl = (_cmsTransformCollection*) _cmsPluginMalloc(id, sizeof(_cmsTransformCollection)); if (fl == NULL) return FALSE; // Copy the parameters @@ -651,6 +651,22 @@ // ---------------------------------------------------------------------------------------------------------------- +static +void SetWhitePoint(cmsCIEXYZ* wtPt, const cmsCIEXYZ* src) +{ + if (src == NULL) { + wtPt ->X = cmsD50X; + wtPt ->Y = cmsD50Y; + wtPt ->Z = cmsD50Z; + } + else { + wtPt ->X = src->X; + wtPt ->Y = src->Y; + wtPt ->Z = src->Z; + } + +} + // New to lcms 2.0 -- have all parameters available. cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID, cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[], @@ -664,7 +680,6 @@ cmsUInt32Number dwFlags) { _cmsTRANSFORM* xform; - cmsBool FloatTransform; cmsColorSpaceSignature EntryColorSpace; cmsColorSpaceSignature ExitColorSpace; cmsPipeline* Lut; @@ -681,9 +696,7 @@ if (hGamutProfile == NULL) dwFlags &= ~cmsFLAGS_GAMUTCHECK; } - // On floating point transforms, inhibit optimizations - FloatTransform = (_cmsFormatterIsFloat(InputFormat) && _cmsFormatterIsFloat(OutputFormat)); - + // On floating point transforms, inhibit cache if (_cmsFormatterIsFloat(InputFormat) || _cmsFormatterIsFloat(OutputFormat)) dwFlags |= cmsFLAGS_NOCACHE; @@ -730,6 +743,10 @@ xform ->ExitColorSpace = ExitColorSpace; xform ->RenderingIntent = Intents[nProfiles-1]; + // Take white points + SetWhitePoint(&xform->EntryWhitePoint, (cmsCIEXYZ*) cmsReadTag(hProfiles[0], cmsSigMediaWhitePointTag)); + SetWhitePoint(&xform->ExitWhitePoint, (cmsCIEXYZ*) cmsReadTag(hProfiles[nProfiles-1], cmsSigMediaWhitePointTag)); + // Create a gamut check LUT if requested if (hGamutProfile != NULL && (dwFlags & cmsFLAGS_GAMUTCHECK))
--- a/src/share/native/sun/java2d/cmm/lcms/lcms2.h Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/lcms2.h Fri May 02 20:39:34 2014 +0100 @@ -30,7 +30,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2011 Marti Maria Saguer +// Copyright (c) 1998-2013 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -52,7 +52,7 @@ // //--------------------------------------------------------------------------------- // -// Version 2.4 +// Version 2.5 // #ifndef _lcms2_H @@ -101,7 +101,7 @@ #endif // Version/release -#define LCMS_VERSION 2040 +#define LCMS_VERSION 2050 // I will give the chance of redefining basic types for compilers that are not fully C99 compliant #ifndef CMS_BASIC_TYPES_ALREADY_DEFINED @@ -367,6 +367,7 @@ cmsSigPreview1Tag = 0x70726531, // 'pre1' cmsSigPreview2Tag = 0x70726532, // 'pre2' cmsSigProfileDescriptionTag = 0x64657363, // 'desc' + cmsSigProfileDescriptionMLTag = 0x6473636d, // 'dscm' cmsSigProfileSequenceDescTag = 0x70736571, // 'pseq' cmsSigProfileSequenceIdTag = 0x70736964, // 'psid' cmsSigPs2CRD0Tag = 0x70736430, // 'psd0' @@ -1014,6 +1015,7 @@ // Plug-In registering --------------------------------------------------------------------------------------------------- CMSAPI cmsBool CMSEXPORT cmsPlugin(void* Plugin); +CMSAPI cmsBool CMSEXPORT cmsPluginTHR(cmsContext ContextID, void* Plugin); CMSAPI void CMSEXPORT cmsUnregisterPlugins(void); // Error logging ---------------------------------------------------------------------------------------------------------- @@ -1190,7 +1192,7 @@ // Where to place/locate the stages in the pipeline chain typedef enum { cmsAT_BEGIN, cmsAT_END } cmsStageLoc; -CMSAPI void CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage* mpe); +CMSAPI int CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage* mpe); CMSAPI void CMSEXPORT cmsPipelineUnlinkStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage** mpe); // This function is quite useful to analyze the structure of a Pipeline and retrieve the Stage elements @@ -1274,6 +1276,13 @@ const char LanguageCode[3], const char CountryCode[3], char ObtainedLanguage[3], char ObtainedCountry[3]); +CMSAPI cmsUInt32Number CMSEXPORT cmsMLUtranslationsCount(const cmsMLU* mlu); + +CMSAPI cmsBool CMSEXPORT cmsMLUtranslationsCodes(const cmsMLU* mlu, + cmsUInt32Number idx, + char LanguageCode[3], + char CountryCode[3]); + // Undercolorremoval & black generation ------------------------------------------------------------------------------------- typedef struct { @@ -1424,6 +1433,7 @@ CMSAPI void CMSEXPORT cmsSetHeaderFlags(cmsHPROFILE hProfile, cmsUInt32Number Flags); CMSAPI cmsUInt32Number CMSEXPORT cmsGetHeaderManufacturer(cmsHPROFILE hProfile); CMSAPI void CMSEXPORT cmsSetHeaderManufacturer(cmsHPROFILE hProfile, cmsUInt32Number manufacturer); +CMSAPI cmsUInt32Number CMSEXPORT cmsGetHeaderCreator(cmsHPROFILE hProfile); CMSAPI cmsUInt32Number CMSEXPORT cmsGetHeaderModel(cmsHPROFILE hProfile); CMSAPI void CMSEXPORT cmsSetHeaderModel(cmsHPROFILE hProfile, cmsUInt32Number model); CMSAPI void CMSEXPORT cmsSetHeaderAttributes(cmsHPROFILE hProfile, cmsUInt64Number Flags);
--- a/src/share/native/sun/java2d/cmm/lcms/lcms2_internal.h Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/java2d/cmm/lcms/lcms2_internal.h Fri May 02 20:39:34 2014 +0100 @@ -27,7 +27,7 @@ // However, the following notice accompanied the original version of this // file: // -//--------------------------------------------------------------------------------- + // // Little Color Management System // Copyright (c) 1998-2011 Marti Maria Saguer @@ -196,7 +196,7 @@ // Plug-In registering --------------------------------------------------------------- // Specialized function for plug-in memory management. No pairing free() since whole pool is freed at once. -void* _cmsPluginMalloc(cmsUInt32Number size); +void* _cmsPluginMalloc(cmsContext ContextID, cmsUInt32Number size); // Memory management cmsBool _cmsRegisterMemHandlerPlugin(cmsPluginBase* Plugin); @@ -205,28 +205,28 @@ cmsBool _cmsRegisterInterpPlugin(cmsPluginBase* Plugin); // Parametric curves -cmsBool _cmsRegisterParametricCurvesPlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterParametricCurvesPlugin(cmsContext ContextID, cmsPluginBase* Plugin); // Formatters management -cmsBool _cmsRegisterFormattersPlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterFormattersPlugin(cmsContext ContextID, cmsPluginBase* Plugin); // Tag type management -cmsBool _cmsRegisterTagTypePlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterTagTypePlugin(cmsContext ContextID, cmsPluginBase* Plugin); // Tag management -cmsBool _cmsRegisterTagPlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterTagPlugin(cmsContext ContextID, cmsPluginBase* Plugin); // Intent management -cmsBool _cmsRegisterRenderingIntentPlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterRenderingIntentPlugin(cmsContext ContextID, cmsPluginBase* Plugin); // Multi Process elements -cmsBool _cmsRegisterMultiProcessElementPlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterMultiProcessElementPlugin(cmsContext ContextID, cmsPluginBase* Plugin); // Optimization -cmsBool _cmsRegisterOptimizationPlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterOptimizationPlugin(cmsContext ContextID, cmsPluginBase* Plugin); // Transform -cmsBool _cmsRegisterTransformPlugin(cmsPluginBase* Plugin); +cmsBool _cmsRegisterTransformPlugin(cmsContext ContextID, cmsPluginBase* Plugin); // --------------------------------------------------------------------------------------------------------- @@ -263,7 +263,7 @@ cmsUInt16Number Country; cmsUInt32Number StrW; // Offset to current unicode string - cmsUInt32Number Len; // Lenght in bytes + cmsUInt32Number Len; // Length in bytes } _cmsMLUentry; @@ -330,9 +330,11 @@ cmsColorSpaceSignature ColorSpace; cmsColorSpaceSignature PCS; cmsUInt32Number RenderingIntent; + cmsUInt32Number flags; cmsUInt32Number manufacturer, model; cmsUInt64Number attributes; + cmsUInt32Number creator; cmsProfileID ProfileID; @@ -585,6 +587,10 @@ cmsColorSpaceSignature EntryColorSpace; cmsColorSpaceSignature ExitColorSpace; + // White points (informative only) + cmsCIEXYZ EntryWhitePoint; + cmsCIEXYZ ExitWhitePoint; + // Profiles used to create the transform cmsSEQ* Sequence;
--- a/src/share/native/sun/management/Flag.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/management/Flag.c Fri May 02 20:39:34 2014 +0100 @@ -95,12 +95,12 @@ return 0; } - if (count == 0) { + if (count <= 0) { JNU_ThrowIllegalArgumentException(env, 0); return 0; } - gsize = count * sizeof(jmmVMGlobal); + gsize = (size_t)count * sizeof(jmmVMGlobal); globals = (jmmVMGlobal*) malloc(gsize); if (globals == NULL) { JNU_ThrowOutOfMemoryError(env, 0);
--- a/src/share/native/sun/management/GcInfoBuilder.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/share/native/sun/management/GcInfoBuilder.c Fri May 02 20:39:34 2014 +0100 @@ -59,12 +59,12 @@ return; } - if (num_attributes == 0) { + if (num_attributes <= 0) { JNU_ThrowIllegalArgumentException(env, "Invalid num_attributes"); return; } - ext_att_info = (jmmExtAttributeInfo*) malloc(num_attributes * + ext_att_info = (jmmExtAttributeInfo*) malloc((size_t)num_attributes * sizeof(jmmExtAttributeInfo)); if (ext_att_info == NULL) { JNU_ThrowOutOfMemoryError(env, 0); @@ -78,7 +78,7 @@ return; } - nativeTypes = (jchar*) malloc(num_attributes * sizeof(jchar)); + nativeTypes = (jchar*) malloc((size_t)num_attributes * sizeof(jchar)); if (nativeTypes == NULL) { free(ext_att_info); JNU_ThrowOutOfMemoryError(env, 0); @@ -188,11 +188,16 @@ return 0; } + if (ext_att_count <= 0) { + JNU_ThrowIllegalArgumentException(env, "Invalid ext_att_count"); + return; + } + gc_stat.usage_before_gc = usageBeforeGC; gc_stat.usage_after_gc = usageAfterGC; gc_stat.gc_ext_attribute_values_size = ext_att_count; if (ext_att_count > 0) { - gc_stat.gc_ext_attribute_values = (jvalue*) malloc(ext_att_count * + gc_stat.gc_ext_attribute_values = (jvalue*) malloc((size_t)ext_att_count * sizeof(jvalue)); if (gc_stat.gc_ext_attribute_values == NULL) { JNU_ThrowOutOfMemoryError(env, 0); @@ -212,7 +217,7 @@ } // convert the ext_att_types to native types - nativeTypes = (jchar*) malloc(ext_att_count * sizeof(jchar)); + nativeTypes = (jchar*) malloc((size_t)ext_att_count * sizeof(jchar)); if (nativeTypes == NULL) { if (gc_stat.gc_ext_attribute_values != NULL) { free(gc_stat.gc_ext_attribute_values);
--- a/src/solaris/classes/sun/awt/X11/XClipboard.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/solaris/classes/sun/awt/X11/XClipboard.java Fri May 02 20:39:34 2014 +0100 @@ -84,7 +84,7 @@ protected synchronized void setContentsNative(Transferable contents) { SortedMap formatMap = DataTransferer.getInstance().getFormatsForTransferable - (contents, DataTransferer.adaptFlavorMap(flavorMap)); + (contents, DataTransferer.adaptFlavorMap(getDefaultFlavorTable())); long[] formats = DataTransferer.keysToLongArray(formatMap); if (!selection.setOwner(contents, formatMap, formats, @@ -123,7 +123,7 @@ private void checkChangeHere(Transferable contents) { if (areFlavorListenersRegistered()) { checkChange(DataTransferer.getInstance(). - getFormatsForTransferableAsArray(contents, flavorMap)); + getFormatsForTransferableAsArray(contents, getDefaultFlavorTable())); } }
--- a/src/solaris/classes/sun/awt/X11/XToolkit.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/solaris/classes/sun/awt/X11/XToolkit.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2014, 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 @@ -49,6 +49,7 @@ import sun.awt.*; import sun.font.FontConfigManager; import sun.misc.PerformanceLogger; +import sun.misc.ThreadGroupUtils; import sun.print.PrintJob2D; import sun.security.action.GetPropertyAction; import sun.security.action.GetBooleanAction; @@ -236,13 +237,7 @@ } PrivilegedAction<Void> a = new PrivilegedAction<Void>() { public Void run() { - ThreadGroup mainTG = Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = mainTG.getParent(); - while (parentTG != null) { - mainTG = parentTG; - parentTG = mainTG.getParent(); - } - Thread shutdownThread = new Thread(mainTG, "XToolkt-Shutdown-Thread") { + Thread shutdownThread = new Thread(ThreadGroupUtils.getRootThreadGroup(), "XToolkt-Shutdown-Thread") { public void run() { XSystemTrayPeer peer = XSystemTrayPeer.getPeerInstance(); if (peer != null) { @@ -304,22 +299,16 @@ init(); XWM.init(); SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME); - - PrivilegedAction<Thread> action = new PrivilegedAction() { + toolkitThread = AccessController.doPrivileged(new PrivilegedAction<Thread>() { + @Override public Thread run() { - ThreadGroup currentTG = Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = currentTG.getParent(); - while (parentTG != null) { - currentTG = parentTG; - parentTG = currentTG.getParent(); - } - Thread thread = new Thread(currentTG, XToolkit.this, "AWT-XAWT"); + Thread thread = new Thread(ThreadGroupUtils.getRootThreadGroup(), XToolkit.this, "AWT-XAWT"); + thread.setContextClassLoader(null); thread.setPriority(Thread.NORM_PRIORITY + 1); thread.setDaemon(true); return thread; } - }; - toolkitThread = AccessController.doPrivileged(action); + }); toolkitThread.start(); } }
--- a/src/solaris/classes/sun/awt/X11GraphicsDevice.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/solaris/classes/sun/awt/X11GraphicsDevice.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, 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 @@ -41,6 +41,7 @@ import sun.java2d.opengl.GLXGraphicsConfig; import sun.java2d.xr.XRGraphicsConfig; import sun.java2d.loops.SurfaceType; +import sun.misc.ThreadGroupUtils; /** * This is an implementation of a GraphicsDevice object for a single @@ -424,23 +425,20 @@ // hook will have no effect) shutdownHookRegistered = true; PrivilegedAction<Void> a = new PrivilegedAction<Void>() { + @Override public Void run() { - ThreadGroup mainTG = Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = mainTG.getParent(); - while (parentTG != null) { - mainTG = parentTG; - parentTG = mainTG.getParent(); - } + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); Runnable r = new Runnable() { - public void run() { - Window old = getFullScreenWindow(); - if (old != null) { - exitFullScreenExclusive(old); - setDisplayMode(origDisplayMode); - } + @Override + public void run() { + Window old = getFullScreenWindow(); + if (old != null) { + exitFullScreenExclusive(old); + setDisplayMode(origDisplayMode); } - }; - Thread t = new Thread(mainTG, r,"Display-Change-Shutdown-Thread-"+screen); + } + }; + Thread t = new Thread(rootTG, r, "Display-Change-Shutdown-Thread-" + screen); t.setContextClassLoader(null); Runtime.getRuntime().addShutdownHook(t); return null;
--- a/src/solaris/demo/jni/Poller/Poller.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/solaris/demo/jni/Poller/Poller.c Fri May 02 20:39:34 2014 +0100 @@ -318,7 +318,7 @@ ioevent_t *ioeh; - if (handle < 0 || handle > MAX_HANDLES) + if (handle < 0 || handle >= MAX_HANDLES) { STATE_EXCEPTION("DestroyPoller - handle out of range"); return; @@ -366,7 +366,7 @@ int retval; ioevent_t *ioeh; - if (handle < 0 || handle > MAX_HANDLES) + if (handle < 0 || handle >= MAX_HANDLES) return STATE_EXCEPTION("AddFd - handle out of range"); ioeh = &IOE_handles[handle]; @@ -459,7 +459,7 @@ return fd; } -/* +/* * Class: Poller * Method: nativeRemoveFd * Signature: (II)I @@ -469,7 +469,7 @@ { ioevent_t *ioeh; - if (handle < 0 || handle > MAX_HANDLES) + if (handle < 0 || handle >= MAX_HANDLES) return STATE_EXCEPTION("RemoveFd - handle out of range"); ioeh = &IOE_handles[handle]; @@ -576,7 +576,7 @@ int i; ioevent_t *ioeh; - if (handle < 0 || handle > MAX_HANDLES) + if (handle < 0 || handle >= MAX_HANDLES) return STATE_EXCEPTION("IsMember - handle out of range"); ioeh = &IOE_handles[handle]; @@ -629,7 +629,7 @@ ioevent_t *ioeh; jboolean isCopy1,isCopy2; - if (handle < 0 || handle > MAX_HANDLES) + if (handle < 0 || handle >= MAX_HANDLES) return STATE_EXCEPTION("nativeWait - handle out of range"); ioeh = &IOE_handles[handle];
--- a/src/solaris/native/com/sun/media/sound/PLATFORM_API_SolarisOS_Utils.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/solaris/native/com/sun/media/sound/PLATFORM_API_SolarisOS_Utils.c Fri May 02 20:39:34 2014 +0100 @@ -76,7 +76,7 @@ adPath[*count].st_ino = statBuf.st_ino; adPath[*count].st_dev = statBuf.st_dev; strncpy(adPath[*count].path, path, MAX_NAME_LENGTH); - adPath[*count].path[MAX_NAME_LENGTH] = 0; + adPath[*count].path[MAX_NAME_LENGTH - 1] = 0; (*count)++; TRACE1("Added audio device %s\n", path); }
--- a/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, 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 @@ -41,6 +41,7 @@ import static sun.awt.shell.Win32ShellFolder2.*; import sun.awt.OSInfo; +import sun.misc.ThreadGroupUtils; // NOTE: This class supersedes Win32ShellFolderManager, which was removed // from distribution after version 1.4.2. @@ -505,23 +506,19 @@ } } }; - comThread = - AccessController.doPrivileged( - new PrivilegedAction<Thread>() { - public Thread run() { + comThread = AccessController.doPrivileged(new PrivilegedAction<Thread>() { + @Override + public Thread run() { /* The thread must be a member of a thread group * which will not get GCed before VM exit. * Make its parent the top-level thread group. */ - ThreadGroup tg = Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; - tg = tgn, tgn = tg.getParent()); - Thread thread = new Thread(tg, comRun, "Swing-Shell"); - thread.setDaemon(true); - return thread; - } - } + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + Thread thread = new Thread(rootTG, comRun, "Swing-Shell"); + thread.setDaemon(true); + return thread; + } + } ); return comThread; }
--- a/src/windows/classes/sun/awt/windows/WClipboard.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/windows/classes/sun/awt/windows/WClipboard.java Fri May 02 20:39:34 2014 +0100 @@ -63,7 +63,6 @@ } protected void setContentsNative(Transferable contents) { - // Don't use delayed Clipboard rendering for the Transferable's data. // If we did that, we would call Transferable.getTransferData on // the Toolkit thread, which is a security hole. @@ -72,7 +71,7 @@ // translated. Then, for each format, translate the data and post // it to the Clipboard. Map formatMap = WDataTransferer.getInstance(). - getFormatsForTransferable(contents, flavorMap); + getFormatsForTransferable(contents, getDefaultFlavorTable()); openClipboard(this);
--- a/src/windows/classes/sun/awt/windows/WToolkit.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/windows/classes/sun/awt/windows/WToolkit.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2014, 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 @@ -37,7 +37,9 @@ import java.security.AccessController; import java.security.PrivilegedAction; import sun.awt.AWTAutoShutdown; +import sun.awt.AppContext; import sun.awt.SunToolkit; +import sun.misc.ThreadGroupUtils; import sun.awt.Win32GraphicsDevice; import sun.awt.Win32GraphicsEnvironment; import sun.java2d.d3d.D3DRenderQueue; @@ -215,7 +217,7 @@ private static native void postDispose(); - private static native boolean startToolkitThread(Runnable thread); + private static native boolean startToolkitThread(Runnable thread, ThreadGroup rootThreadGroup); public WToolkit() { // Startup toolkit threads @@ -232,8 +234,15 @@ */ AWTAutoShutdown.notifyToolkitThreadBusy(); - if (!startToolkitThread(this)) { - Thread toolkitThread = new Thread(this, "AWT-Windows"); + // Find a root TG and attach Appkit thread to it + ThreadGroup rootTG = AccessController.doPrivileged(new PrivilegedAction<ThreadGroup>() { + @Override + public ThreadGroup run() { + return ThreadGroupUtils.getRootThreadGroup(); + } + }); + if (!startToolkitThread(this, rootTG)) { + Thread toolkitThread = new Thread(rootTG, this, "AWT-Windows"); toolkitThread.setDaemon(true); toolkitThread.start(); } @@ -263,14 +272,7 @@ private final void registerShutdownHook() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - ThreadGroup currentTG = - Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = currentTG.getParent(); - while (parentTG != null) { - currentTG = parentTG; - parentTG = currentTG.getParent(); - } - Thread shutdown = new Thread(currentTG, new Runnable() { + Thread shutdown = new Thread(ThreadGroupUtils.getRootThreadGroup(), new Runnable() { public void run() { shutdown(); } @@ -283,7 +285,14 @@ } public void run() { - Thread.currentThread().setPriority(Thread.NORM_PRIORITY+1); + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + Thread.currentThread().setContextClassLoader(null); + return null; + } + }); + Thread.currentThread().setPriority(Thread.NORM_PRIORITY + 1); boolean startPump = init(); if (startPump) { @@ -855,7 +864,18 @@ * Windows doesn't always send WM_SETTINGCHANGE when it should. */ private void windowsSettingChange() { - updateProperties(); + if (AppContext.getAppContext() == null) { + // No AppContext, so we can update properties on the current thread, + // DesktopPropertyChangeSupport will only post events. + updateProperties(); + } else { + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + updateProperties(); + } + }); + } } private synchronized void updateProperties() {
--- a/src/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java Wed Apr 30 15:40:34 2014 +0100 +++ b/src/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java Fri May 02 20:39:34 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2014, 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 @@ -36,8 +36,9 @@ import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; -import sun.awt.SunToolkit; + import sun.awt.AWTAccessor; +import sun.misc.ThreadGroupUtils; import sun.awt.Win32GraphicsConfig; import sun.awt.windows.WComponentPeer; import sun.java2d.InvalidPipeException; @@ -92,30 +93,26 @@ public D3DScreenUpdateManager() { done = false; AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - ThreadGroup currentTG = - Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = currentTG.getParent(); - while (parentTG != null) { - currentTG = parentTG; - parentTG = currentTG.getParent(); - } - Thread shutdown = new Thread(currentTG, new Runnable() { + new PrivilegedAction<Void>() { + @Override + public Void run() { + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + Thread shutdown = new Thread(rootTG, new Runnable() { + @Override public void run() { done = true; wakeUpUpdateThread(); } }); - shutdown.setContextClassLoader(null); - try { - Runtime.getRuntime().addShutdownHook(shutdown); - } catch (Exception e) { - done = true; + shutdown.setContextClassLoader(null); + try { + Runtime.getRuntime().addShutdownHook(shutdown); + } catch (Exception e) { + done = true; + } + return null; } - return null; } - } ); } @@ -354,21 +351,20 @@ */ private synchronized void startUpdateThread() { if (screenUpdater == null) { - screenUpdater = (Thread)java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - ThreadGroup tg = - Thread.currentThread().getThreadGroup(); - for (ThreadGroup tgn = tg; - tgn != null; tg = tgn, tgn = tg.getParent()); - Thread t = new Thread(tg, D3DScreenUpdateManager.this, - "D3D Screen Updater"); - // REMIND: should it be higher? - t.setPriority(Thread.NORM_PRIORITY + 2); - t.setDaemon(true); - return t; - } - }); + screenUpdater = AccessController.doPrivileged( + new PrivilegedAction<Thread>() { + @Override + public Thread run() { + ThreadGroup rootTG = ThreadGroupUtils.getRootThreadGroup(); + Thread t = new Thread(rootTG, + D3DScreenUpdateManager.this, + "D3D Screen Updater"); + // REMIND: should it be higher? + t.setPriority(Thread.NORM_PRIORITY + 2); + t.setDaemon(true); + return t; + } + }); screenUpdater.start(); } else { wakeUpUpdateThread();
--- a/src/windows/native/sun/font/fontpath.c Wed Apr 30 15:40:34 2014 +0100 +++ b/src/windows/native/sun/font/fontpath.c Fri May 02 20:39:34 2014 +0100 @@ -185,6 +185,12 @@ return 0; } +/* This HDC is initialised and released in the populate family map + * JNI entry point, and used within the call which would otherwise + * create many DCs. + */ +static HDC screenDC = NULL; + static int DifferentFamily(wchar_t *family, wchar_t* fullName) { LOGFONTW lfw; CheckFamilyInfo info; @@ -202,7 +208,7 @@ memset(&lfw, 0, sizeof(lfw)); wcscpy(lfw.lfFaceName, fullName); lfw.lfCharSet = DEFAULT_CHARSET; - EnumFontFamiliesExW(GetDC(NULL), &lfw, + EnumFontFamiliesExW(screenDC, &lfw, (FONTENUMPROCW)CheckFontFamilyProcW, (LPARAM)(&info), 0L); @@ -299,7 +305,7 @@ memset(&lfa, 0, sizeof(lfa)); strcpy(lfa.lfFaceName, lpelfe->elfLogFont.lfFaceName); lfa.lfCharSet = lpelfe->elfLogFont.lfCharSet; - EnumFontFamiliesExA(GetDC(NULL), &lfa, + EnumFontFamiliesExA(screenDC, &lfa, (FONTENUMPROCA)EnumFontFacesInFamilyProcA, lParam, 0L); return 1; @@ -353,7 +359,7 @@ memset(&lfw, 0, sizeof(lfw)); wcscpy(lfw.lfFaceName, lpelfe->elfLogFont.lfFaceName); lfw.lfCharSet = lpelfe->elfLogFont.lfCharSet; - EnumFontFamiliesExW(GetDC(NULL), &lfw, + EnumFontFamiliesExW(screenDC, &lfw, (FONTENUMPROCW)EnumFontFacesInFamilyProcW, lParam, 0L); return 1; @@ -613,13 +619,17 @@ return; } + screenDC = GetDC(NULL); + if (screenDC == NULL) { + return; + } /* Enumerate fonts via GDI to build maps of fonts and families */ if (IS_NT) { LOGFONTW lfw; memset(&lfw, 0, sizeof(lfw)); lfw.lfCharSet = DEFAULT_CHARSET; /* all charsets */ wcscpy(lfw.lfFaceName, L""); /* one face per family (CHECK) */ - EnumFontFamiliesExW(GetDC(NULL), &lfw, + EnumFontFamiliesExW(screenDC, &lfw, (FONTENUMPROCW)EnumFamilyNamesW, (LPARAM)(&fmi), 0L); } else { @@ -627,7 +637,7 @@ memset(&lfa, 0, sizeof(lfa)); lfa.lfCharSet = DEFAULT_CHARSET; /* all charsets */ strcpy(lfa.lfFaceName, ""); /* one face per family */ - ret = EnumFontFamiliesExA(GetDC(NULL), &lfa, + ret = EnumFontFamiliesExA(screenDC, &lfa, (FONTENUMPROCA)EnumFamilyNamesA, (LPARAM)(&fmi), 0L); } @@ -637,6 +647,8 @@ ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, fontKeyName, 0L, KEY_READ, &hkeyFonts); if (ret != ERROR_SUCCESS) { + ReleaseDC(NULL, screenDC); + screenDC = NULL; return; } @@ -653,6 +665,8 @@ dwMaxValueNameLen >= MAX_BUFFER || dwMaxValueDataLen >= MAX_BUFFER) { RegCloseKey(hkeyFonts); + ReleaseDC(NULL, screenDC); + screenDC = NULL; return; } for (nval = 0; nval < dwNumValues; nval++ ) { @@ -692,4 +706,6 @@ } } RegCloseKey(hkeyFonts); + ReleaseDC(NULL, screenDC); + screenDC = NULL; }
--- a/src/windows/native/sun/windows/awt_Toolkit.cpp Wed Apr 30 15:40:34 2014 +0100 +++ b/src/windows/native/sun/windows/awt_Toolkit.cpp Fri May 02 20:39:34 2014 +0100 @@ -365,6 +365,7 @@ HANDLE hCompleted; jobject thread; + jobject threadGroup; }; void ToolkitThreadProc(void *param) @@ -377,7 +378,7 @@ JavaVMAttachArgs attachArgs; attachArgs.version = JNI_VERSION_1_2; attachArgs.name = "AWT-Windows"; - attachArgs.group = NULL; + attachArgs.group = data->threadGroup; jint res = jvm->AttachCurrentThreadAsDaemon((void **)&env, &attachArgs); if (res < 0) { @@ -416,17 +417,18 @@ /* * Class: sun_awt_windows_WToolkit * Method: startToolkitThread - * Signature: (Ljava/lang/Runnable;)Z + * Signature: (Ljava/lang/Runnable;Ljava/lang/ThreadGroup)Z */ JNIEXPORT jboolean JNICALL -Java_sun_awt_windows_WToolkit_startToolkitThread(JNIEnv *env, jclass cls, jobject thread) +Java_sun_awt_windows_WToolkit_startToolkitThread(JNIEnv *env, jclass cls, jobject thread, jobject threadGroup) { AwtToolkit& tk = AwtToolkit::GetInstance(); ToolkitThreadProc_Data data; data.result = false; data.thread = env->NewGlobalRef(thread); - if (data.thread == NULL) { + data.threadGroup = env->NewGlobalRef(threadGroup); + if (data.thread == NULL || data.threadGroup == NULL) { return JNI_FALSE; } data.hCompleted = ::CreateEvent(NULL, FALSE, FALSE, NULL); @@ -444,6 +446,7 @@ ::CloseHandle(data.hCompleted); env->DeleteGlobalRef(data.thread); + env->DeleteGlobalRef(data.threadGroup); return result ? JNI_TRUE : JNI_FALSE; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Graphics2D/DrawString/DrawRotatedString.java Fri May 02 20:39:34 2014 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013, 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. + * + * 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. + */ + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +/** + * @test + * @bug 7190349 + * @summary Verifies that we get correct direction, when draw rotated string. + * @author Sergey Bylokhov + * @run main/othervm DrawRotatedString + */ +public final class DrawRotatedString { + + private static final int SIZE = 500; + + public static void main(final String[] args) throws IOException { + BufferedImage bi = createBufferedImage(true); + verify(bi); + bi = createBufferedImage(false); + verify(bi); + System.out.println("Passed"); + } + + private static void verify(BufferedImage bi) throws IOException { + for (int i = 0; i < SIZE; ++i) { + for (int j = 0; j < 99; ++j) { + //Text should not appear before 100 + if (bi.getRGB(i, j) != Color.RED.getRGB()) { + ImageIO.write(bi, "png", new File("image.png")); + throw new RuntimeException("Failed: wrong text location"); + } + } + } + } + + private static BufferedImage createBufferedImage(final boolean aa) { + final BufferedImage bi = new BufferedImage(SIZE, SIZE, + BufferedImage.TYPE_INT_RGB); + final Graphics2D bg = bi.createGraphics(); + bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + aa ? RenderingHints.VALUE_ANTIALIAS_ON + : RenderingHints.VALUE_ANTIALIAS_OFF); + bg.setColor(Color.RED); + bg.fillRect(0, 0, SIZE, SIZE); + bg.translate(100, 100); + bg.rotate(Math.toRadians(90)); + bg.setColor(Color.BLACK); + bg.setFont(bg.getFont().deriveFont(20.0f)); + bg.drawString("MMMMMMMMMMMMMMMM", 0, 0); + bg.dispose(); + return bi; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Graphics2D/IncorrectTextSize/IncorrectTextSize.java Fri May 02 20:39:34 2014 +0100 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2013, 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. + * + * 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. + */ + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +/** + * @test + * @bug 8013569 + * @author Sergey Bylokhov + */ +public final class IncorrectTextSize { + + static final int scale = 2; + static final int width = 1200; + static final int height = 100; + static BufferedImage bi = new BufferedImage(width, height, + BufferedImage.TYPE_INT_ARGB); + static final String TEXT = "The quick brown fox jumps over the lazy dog" + + "The quick brown fox jumps over the lazy dog"; + + public static void main(final String[] args) throws IOException { + for (int point = 5; point < 11; ++point) { + Graphics2D g2d = bi.createGraphics(); + g2d.setFont(new Font(Font.DIALOG, Font.PLAIN, point)); + g2d.scale(scale, scale); + g2d.setColor(Color.WHITE); + g2d.fillRect(0, 0, width, height); + g2d.setColor(Color.green); + g2d.drawString(TEXT, 0, 20); + int length = g2d.getFontMetrics().stringWidth(TEXT); + if (length < 0) { + throw new RuntimeException("Negative length"); + } + for (int i = (length + 1) * scale; i < width; ++i) { + for (int j = 0; j < height; ++j) { + if (bi.getRGB(i, j) != Color.white.getRGB()) { + g2d.drawLine(length, 0, length, height); + ImageIO.write(bi, "png", new File("image.png")); + System.out.println("length = " + length); + System.err.println("Wrong color at x=" + i + ",y=" + j); + System.err.println("Color is:" + new Color(bi.getRGB(i, + j))); + throw new RuntimeException("Test failed."); + } + } + } + g2d.dispose(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Toolkit/LoadAWTCrashTest/LoadAWTCrashTest.java Fri May 02 20:39:34 2014 +0100 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, 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. + * + * 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. + */ + +/* + @test + @bug 8031477 + @summary Crash while awt starting + @author Petr Pchelko + @run main/othervm LoadAWTCrashTest +*/ + +public class LoadAWTCrashTest { + public static void main(String[] args) { + System.loadLibrary("awt"); + // If the bug is present JVM would crash or deadlock + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/font/TextLayout/TestAATMorxFont.java Fri May 02 20:39:34 2014 +0100 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2014, 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. + * + * 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. + * + */ + +/* @test + * @summary verify rendering of MORX fonts on OS X. + * @bug 8031462 + */ + +import javax.swing.*; +import javax.swing.border.LineBorder; +import java.awt.*; +import java.awt.event.ActionEvent; + +public class TestAATMorxFont extends JComponent { + public static void main(String[] args) { + String osName = System.getProperty("os.name"); + System.out.println("OS is " + osName); + osName = osName.toLowerCase(); + if (!osName.startsWith("mac")) { + return; + } + SwingUtilities.invokeLater(new Runnable() { + public void run() { + JFrame frame = new JFrame("Test Morx"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + TestAATMorxFont panel = new TestAATMorxFont(); + frame.add(panel); + frame.pack(); + frame.setVisible(true); + } + }); + } + + public Dimension getPreferredSize() { + return new Dimension(1200, 400); + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D)g; + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + int y = 50; + g.setFont(new Font("Gujarati MT", Font.PLAIN, 40)); + System.out.println(g.getFont()); + g.drawString("\u0A95\u0ACD \u0A95\u0A95\u0A95 \u0A95\u0ACD\u0A95\u0ACD\u0A95", 20, y); + y += 50; + g.setFont(new Font("Tamil Sangam MN", Font.PLAIN, 40)); + System.out.println(g.getFont()); + g.drawString("\u0b95\u0bCD \u0b95\u0b95\u0b95 \u0b95\u0bCD\u0b95\u0bCD\u0b95", 20, y); + y += 50; + g.setFont(new Font("Telugu Sangam MN", Font.PLAIN, 40)); + System.out.println(g.getFont()); + g.drawString("\u0c15\u0c4D \u0c15\u0c15\u0c15 \u0c15\u0c4D\u0c15\u0c4D\u0c15", 20, y); + y += 50; + g.setFont(new Font("Devanagari Sangam MN", Font.PLAIN, 40)); + System.out.println(g.getFont()); + g.drawString("\u0915\u0940 \u0915\u0947 \u0915\u0942", 20, y); + y += 50; + g.drawString("\u0907\u0930\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915", 20, y); + y += 50; + g.drawString("\u0930\u093F\u0935\u094D\u092F\u0942 \u0915\u0947 \u092C\u093E\u0926 \u0935\u093F\u0915\u093E\u0938 \u0913\u0932\u0902\u092A\u093F\u0915 \u0938\u0947 \u092C\u093E\u0939\u0930 (\u0926\u0947\u0935\u0928\u093E\u0917\u0930\u0940) (\u0939\u093F\u0928\u094D\u0926\u0940) \u0907\u0930\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915\u094D\u0915", 20, y); + + } +} +
--- a/test/java/beans/Introspector/TestTypeResolver.java Wed Apr 30 15:40:34 2014 +0100 +++ b/test/java/beans/Introspector/TestTypeResolver.java Fri May 02 20:39:34 2014 +0100 @@ -113,6 +113,8 @@ // by private implementations of the various Type interfaces if (expect.equals(t) && t.equals(expect)) System.out.println(", as expected"); + else if ((expect.equals(t) || t.equals(expect)) && expect.toString().equals(t.toString())) + System.out.println(", as workaround of the 8023301 bug"); else { System.out.println(" BUT SHOULD BE " + expect); failedCases.add(c);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/imageio/plugins/jpeg/TruncatedImageWarningTest.java Fri May 02 20:39:34 2014 +0100 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, 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. + * + * 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. + */ + +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.event.IIOReadWarningListener; +import javax.imageio.stream.ImageInputStream; + +public class TruncatedImageWarningTest implements IIOReadWarningListener { + + private static String fileName = "truncated.jpg"; + boolean receivedWarning = false; + + public static void main(String[] args) throws IOException { + + String sep = System.getProperty("file.separator"); + String dir = System.getProperty("test.src", "."); + String filePath = dir+sep+fileName; + System.out.println("Test file: " + filePath); + File f = new File(filePath); + ImageInputStream in = ImageIO.createImageInputStream(f); + ImageReader reader = ImageIO.getImageReaders(in).next(); + TruncatedImageWarningTest twt = new TruncatedImageWarningTest(); + reader.addIIOReadWarningListener(twt); + reader.setInput(in); + reader.read(0); + if (!twt.receivedWarning) { + throw new RuntimeException("No expected warning"); + } + } + + public void warningOccurred(ImageReader source, String warning) { + System.out.println("Expected warning: " + warning); + receivedWarning = true; + } +}