Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8297480: GetPrimitiveArrayCritical in imageioJPEG misses result - NULL check #11312

Closed
wants to merge 1 commit into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Nov 23, 2022

Seems there is a remaining GetPrimitiveArrayCritical in imageioJPEG that misses a result - NULL check, this should be added.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8297480: GetPrimitiveArrayCritical in imageioJPEG misses result - NULL check

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/11312/head:pull/11312
$ git checkout pull/11312

Update a local copy of the PR:
$ git checkout pull/11312
$ git pull https://git.openjdk.org/jdk pull/11312/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11312

View PR using the GUI difftool:
$ git pr show -t 11312

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11312.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 23, 2022

👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 23, 2022
@openjdk
Copy link

openjdk bot commented Nov 23, 2022

@MBaesken The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Nov 23, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 23, 2022

Webrevs

@jayathirthrao
Copy link
Member

Did we actually hit null pointer issue in some specific condition using ImageIO or this bug got identified because of some static analysis?

@MBaesken
Copy link
Member Author

Did we actually hit null pointer issue in some specific condition using ImageIO or this bug got identified because of some static analysis?

I just grepped the codebase for GetPrimitiveArrayCritical usages and while doing so saw this.

@jayathirthrao
Copy link
Member

Thanks for the fix. Change looks good to me.
I am running ImageIO tests with fix and will approve soon. There should not be any issues.

@MBaesken
Copy link
Member Author

MBaesken commented Nov 23, 2022

Hello , I did a few more grepping and source reading and while 98 or 99 percent of the GetPrimitiveArrayCritical return values are checked, there are a few more unchecked ones. See below

`
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-136- jint nElements = (*env)->GetArrayLength(env, inTypes);
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-137- NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:nElements];
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m:138: jlong *elements = (*env)->GetPrimitiveArrayCritical(env, inTypes, NULL);
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-139-
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-140- for (i = 0; i < nElements; i++) {
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-141- NSString *pbFormat = formatForIndex(elements[i]);
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-142- if (pbFormat)
src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-143- [formatArray addObject:pbFormat];

src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-54-static inline void
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-55-GetGlyphsFromUnicodes(JNIEnv *env, AWTFont *awtFont,
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-56- jint count, UniChar *unicodes,
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-57- CGGlyph *cgGlyphs, jintArray glyphs)
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-58-{
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m:59: jint *glyphCodeInts = (*env)->GetPrimitiveArrayCritical(env, glyphs, 0);
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-60-
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-61- CTS_GetGlyphsAsIntsForCharacters(awtFont, unicodes,
src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-62- cgGlyphs, glyphCodeInts, count);

src/java.desktop/macosx/native/libosxui/JRSUIController.m:279: jdouble *rect = (*env)->GetPrimitiveArrayCritical(env, rectArray, NULL);
src/java.desktop/macosx/native/libosxui/JRSUIController.m-280- rect[0] = partBounds.origin.x;
src/java.desktop/macosx/native/libosxui/JRSUIController.m-281- rect[1] = partBounds.origin.y;

src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-333-Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting(
src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-334- JNIEnv *env, jobject this, jintArray dest, jint width, jint height)
src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-335-{
src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-336- jint transparency;
src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c:337: gint buffer = (gint) (*env)->GetPrimitiveArrayCritical(env, dest, 0);
src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-338- gtk->gdk_threads_enter();
src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-339- transparency = gtk->copy_image(buffer, width, height);

src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-437- // Copy the resulting pixels to our Java BufferedImage.
src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp:438: pDstBits = (int *)env->GetPrimitiveArrayCritical(array, 0);
src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-439- BOOL transparent = FALSE;
src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-440- transparent = IsThemeBackgroundPartiallyTransparentFunc(hTheme, part, state);
src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-441- copyDIBToBufferedImage(pDstBits, pSrcBits, transparent, w, h, stride);
src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-442- env->ReleasePrimitiveArrayCritical(array, pDstBits, 0);

src/java.desktop/windows/native/libawt/windows/awt_DataTransferer.cpp-164- LOGPALETTE* pLogPalette =
src/java.desktop/windows/native/libawt/windows/awt_DataTransferer.cpp:165: (LOGPALETTE*)env->GetPrimitiveArrayCritical(paletteBytes, NULL);
src/java.desktop/windows/native/libawt/windows/awt_DataTransferer.cpp-166- PALETTEENTRY* pPalEntries = (PALETTEENTRY*)pLogPalette->palPalEntry;

src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp:2863: colorsPtr = (jint *)env->GetPrimitiveArrayCritical(colors, 0);
src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp-2864- for (int i = 0; i < (sizeof indexMap)/(sizeof *indexMap) && i < colorLen; i++) {
src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp-2865- colorsPtr[i] = DesktopColor2RGB(indexMap[i]);
src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp-2866- }
`

Should I open another jbs issue for them ?

@kiraka42
Copy link

kiraka42 commented Nov 23, 2022

some tests are failing

@MBaesken
Copy link
Member Author

MBaesken commented Nov 23, 2022

Yes some Windows tests are failing; however it seems they miss getting the BOOT JDK or other components for example
https://github.com/MBaesken/jdk/actions/runs/3530303514/jobs/5923400590

so this looks not related to me.

@jayathirthrao
Copy link
Member

Hello , I did a few more grepping and source reading and while 98 or 99 percent of the GetPrimitiveArrayCritical return values are checked, there are a few more unchecked ones. See below

` src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-136- jint nElements = (*env)->GetArrayLength(env, inTypes); src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-137- NSMutableArray *formatArray = [NSMutableArray arrayWithCapacity:nElements]; src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m:138: jlong *elements = (*env)->GetPrimitiveArrayCritical(env, inTypes, NULL); src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-139- src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-140- for (i = 0; i < nElements; i++) { src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-141- NSString *pbFormat = formatForIndex(elements[i]); src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-142- if (pbFormat) src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m-143- [formatArray addObject:pbFormat];

src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-54-static inline void src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-55-GetGlyphsFromUnicodes(JNIEnv *env, AWTFont *awtFont, src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-56- jint count, UniChar *unicodes, src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-57- CGGlyph *cgGlyphs, jintArray glyphs) src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-58-{ src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m:59: jint *glyphCodeInts = (*env)->GetPrimitiveArrayCritical(env, glyphs, 0); src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-60- src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-61- CTS_GetGlyphsAsIntsForCharacters(awtFont, unicodes, src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m-62- cgGlyphs, glyphCodeInts, count);

src/java.desktop/macosx/native/libosxui/JRSUIController.m:279: jdouble *rect = (*env)->GetPrimitiveArrayCritical(env, rectArray, NULL); src/java.desktop/macosx/native/libosxui/JRSUIController.m-280- rect[0] = partBounds.origin.x; src/java.desktop/macosx/native/libosxui/JRSUIController.m-281- rect[1] = partBounds.origin.y;

src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-333-Java_com_sun_java_swing_plaf_gtk_GTKEngine_nativeFinishPainting( src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-334- JNIEnv *env, jobject this, jintArray dest, jint width, jint height) src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-335-{ src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-336- jint transparency; src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c:337: gint buffer = (gint) (*env)->GetPrimitiveArrayCritical(env, dest, 0); src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-338- gtk->gdk_threads_enter(); src/java.desktop/unix/native/libawt_xawt/awt/swing_GTKEngine.c-339- transparency = gtk->copy_image(buffer, width, height);

src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-437- // Copy the resulting pixels to our Java BufferedImage. src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp:438: pDstBits = (int *)env->GetPrimitiveArrayCritical(array, 0); src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-439- BOOL transparent = FALSE; src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-440- transparent = IsThemeBackgroundPartiallyTransparentFunc(hTheme, part, state); src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-441- copyDIBToBufferedImage(pDstBits, pSrcBits, transparent, w, h, stride); src/java.desktop/windows/native/libawt/windows/ThemeReader.cpp-442- env->ReleasePrimitiveArrayCritical(array, pDstBits, 0);

src/java.desktop/windows/native/libawt/windows/awt_DataTransferer.cpp-164- LOGPALETTE* pLogPalette = src/java.desktop/windows/native/libawt/windows/awt_DataTransferer.cpp:165: (LOGPALETTE*)env->GetPrimitiveArrayCritical(paletteBytes, NULL); src/java.desktop/windows/native/libawt/windows/awt_DataTransferer.cpp-166- PALETTEENTRY* pPalEntries = (PALETTEENTRY*)pLogPalette->palPalEntry;

src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp:2863: colorsPtr = (jint *)env->GetPrimitiveArrayCritical(colors, 0); src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp-2864- for (int i = 0; i < (sizeof indexMap)/(sizeof *indexMap) && i < colorLen; i++) { src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp-2865- colorsPtr[i] = DesktopColor2RGB(indexMap[i]); src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp-2866- } `

Should I open another jbs issue for them ?

Sure please create new JBS issue for the same.

@openjdk
Copy link

openjdk bot commented Nov 23, 2022

@MBaesken This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8297480: GetPrimitiveArrayCritical in imageioJPEG misses result - NULL check

Reviewed-by: jdv

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 6 new commits pushed to the master branch:

  • e6e57fe: 8297507: Update header after JDK-8297230
  • bc59f2a: 8295984: Remove unexpected JShell feature
  • 0d93ab9: 8297000: [jib] Add more friendly warning for proxy issues
  • 5b3d86f: 8297230: Update Marlin2D to 0.9.4.6
  • f4b5065: 8297435: Remove unused CompactibleSpaceClosure
  • bde0e35: 8297142: jdk/jfr/event/runtime/TestShutdown.java fails on Linux ppc64le and Linux aarch64

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 23, 2022
@MBaesken
Copy link
Member Author

Thanks for the review !

/integrate

@openjdk
Copy link

openjdk bot commented Nov 24, 2022

Going to push as commit 2f8a5c2.
Since your change was applied there have been 14 commits pushed to the master branch:

  • abeddab: 6528710: sRGB-ColorSpace to sRGB-ColorSpace Conversion
  • 09ac9eb: 8297533: ProblemList java/io/File/TempDirDoesNotExist.java test failing on windows-x64
  • 5325145: 8297529: ProblemList javax/swing/JFileChooser/8046391/bug8046391.java on windows-x64
  • 91cd8a0: 8297525: jdk/jshell/ToolBasicTest.java fails after JDK-8295984
  • 6dc4d89: 7181214: Need specify SKF translateKey(SecurityKey) method requires instance of PBEKey for PBKDF2 algorithms
  • 2afb4c3: 8297338: JFR: RemoteRecordingStream doesn't respect setMaxAge and setMaxSize
  • 8df3bc4: 8290313: Produce warning when user specified java.io.tmpdir directory doesn't exist
  • 086763a: 8297154: Improve safepoint cleanup logging
  • e6e57fe: 8297507: Update header after JDK-8297230
  • bc59f2a: 8295984: Remove unexpected JShell feature
  • ... and 4 more: https://git.openjdk.org/jdk/compare/f26bd4e0e8b68de297a9ff93526cd7fac8668320...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 24, 2022
@openjdk openjdk bot closed this Nov 24, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 24, 2022
@openjdk
Copy link

openjdk bot commented Nov 24, 2022

@MBaesken Pushed as commit 2f8a5c2.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
3 participants