JDK-8011950 : java.io.File.createTempFile enters infinite loop when passed invalid data
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6,7u7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-03-20
  • Updated: 2014-11-17
  • Resolved: 2013-06-10
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 6 JDK 7 JDK 8
6u85Fixed 7u40Fixed 8 b96Fixed
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_07 " 
Java(TM) SE Runtime Environment (build 1.7.0_07-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
java.io.File.createTempFile() can enter into an infinite loop if passed bad
arguments. Rather than entering an infinite loop, it should throw an
Exception to indicate that bad arguments had been passed.

This potentially could result in a denial of service - suppose some program
provides a way to vary the arguments passed to createTempFile() -
admittedly not good practice, and possibly a securtiy issue in itself - but suppose
such a program existed, one could cause it to enter an infinite loop by
providing bad arguments.

createTempFile() should check its arguments for directory separators
(i.e. / or \)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Compile the program provided below with javac
2) Run the program with java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
createTempFile() should throw an exception to indicate bad arguments were passed
ACTUAL -
Enters an infinite loop and never returns


ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class BugRepo {
  public static void main(String[] args) throws Exception {
    java.io.File.createTempFile( " ///../// " ,  " ///..///.. " );
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
If one is concerned about this, wrap File.createTempFile() in a wrapper
which checks the validity of its arguments.