JDK-8262829 : Native crash in Win32PrintServiceLookup.getAllPrinterNames()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7,8,8u271,11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2021-03-02
  • Updated: 2021-06-02
  • Resolved: 2021-03-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 13 JDK 15 JDK 16 JDK 17 JDK 7 JDK 8 Other
11.0.12Fixed 13.0.8Fixed 15.0.4Fixed 16.0.2Fixed 17 b13Fixed 7u311Fixed 8u281Fixed openjdk8u312Unresolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
Java native crash in Win32PrintServiceLookup.getAllPrinterNames()

The crash happens when the JVM tries to refresh the printers from the OS. The class sun.print.Win32PrintServiceLookup defines a native method 'getAllPrinterNames()' and the crash happens inside that method.
Comments
Fix Request (8u): Backport to 8u requested because it is a part of 8u301-oracle. Patch applies cleanly after paths changes. Testing: jtreg:javax/print, jck:api/javax_print. Exported 8u changeset: https://cr.openjdk.java.net/~akasko/jdk8u/8262829/8262829_8u.patch
02-06-2021

Fix request (15u): this fix should be ported here, too. Applies cleanly.
19-05-2021

Fix request (13u) I'd like to port it to jdk13u, too. The regular nightly testing runs OK. Applies clean.
19-05-2021

Fix Request (11u) Should get backported for parity with 11.0.12-oracle. Applies cleanly.
16-03-2021

JDK-8240518 and JDK-8241829 were also backported with this fix to make printer handling code up-to-date across Java release families.
16-03-2021

Changeset: a6e34b3d Author: Alexey Ivanov <aivanov@openjdk.org> Date: 2021-03-09 11:36:30 +0000 URL: https://git.openjdk.java.net/jdk/commit/a6e34b3d
09-03-2021

Fix Request (16u) - Justification: Prevent a crash in native code when updating the list of printers - Risk Analysis: Low, check return value of EnumPrinters function - Testing: No specific testing; tests which use printers on Windows use this code path The patch from jdk-dev (17) applies cleanly to 16u.
09-03-2021

Root cause: getPrinterNames() has two calls to ::EnumPrinters. The first call is to get the required buffer size to contain the structures and any strings. The second call is to get the list of printers. Yet the list of printers or the names of printers can change between the two calls. If it happens, the second call to EnumPrinters fails but it is not checked. I couldn't reproduce the crash myself. However, I reproduced the failure in the second call to ::EnumPrinters by adding ::Sleep(500) and by renaming the printers so that the data doesn't fit into the allocated buffer: 1: bResult: 0, cbNeeded: 504, cReturned: 0 2: bResult: 0, cbNeeded: 512, cReturned: 0 !!! error During my testing, cReturned has always been zero whenever EnumPrinters fails. The crash dumps show that cReturned is non-zero but the pPrinterEnum buffer doesn't contain valid data. Reading info4->pPrinterName at the line utf_str = JNU_NewStringPlatform(env, info4->pPrinterName); raises Access Violation exception.
04-03-2021

Stack trace from hs_err*.log file: Stack: [0x455c0000,0x45610000], sp=0x4560f10c, free space=316k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [ucrtbase.dll+0x42e67] C [awt.dll+0x72030] C [awt.dll+0x70cde] j sun.print.Win32PrintServiceLookup.refreshServices()V+2 j sun.print.Win32PrintServiceLookup.access$200(Lsun/print/Win32PrintServiceLookup;)V+1 j sun.print.Win32PrintServiceLookup$PrinterChangeListener.run()V+29 j java.lang.Thread.run()V+11 v ~StubRoutines::call_stub V [jvm.dll+0x165e44] V [jvm.dll+0x236b5b] V [jvm.dll+0x1665f7] V [jvm.dll+0x166536] V [jvm.dll+0x101c0b] V [jvm.dll+0x18a624] V [jvm.dll+0x1cfa9b] C [ucrtbase.dll+0x407af] C [KERNEL32.DLL+0x162c4] C [ntdll.dll+0x60779] C [ntdll.dll+0x60744] C 0x00000000 Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j sun.print.Win32PrintServiceLookup.getAllPrinterNames()[Ljava/lang/String;+0 j sun.print.Win32PrintServiceLookup.refreshServices()V+2 j sun.print.Win32PrintServiceLookup.access$200(Lsun/print/Win32PrintServiceLookup;)V+1 j sun.print.Win32PrintServiceLookup$PrinterChangeListener.run()V+29 j java.lang.Thread.run()V+11 v ~StubRoutines::call_stub
04-03-2021

This bug reports the crash which is also reported in JDK-6996051 and JDK-8182683.
04-03-2021