Bug #77368 "LOAD DATA LOCAL INFILE” doesn't work properly with relative paths
Submitted: 16 Jun 2015 8:35 Modified: 25 Jun 2015 18:18
Reporter: Jakub Denk Email Updates:
Status: Verified Impact on me:
Category:Connector / J Severity:S2 (Serious)
Version:5.1.35 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[16 Jun 2015 8:35] Jakub Denk
When I try to use the command like this: "LOAD DATA LOCAL INFILE ./data/file.csv", mysql driver doesn't resolve it against the java system property "user.dir", as it should.

The root cause is in the class com.mysql.jdbc.MysqlIO. The code, constructing InputStream looks like this:

  } else if (!this.connection.getAllowUrlInLocalInfile()) {
                fileIn = new BufferedInputStream(new FileInputStream(fileName));

But regarding this "feature" (more likely bug) in java itself : http://bugs.java.com/bugdatabase/view_bug.do;:YfiG?bug_id=4483097 
the code should look like this:

  } else if (!this.connection.getAllowUrlInLocalInfile()) {
                fileIn = new BufferedInputStream(new FileInputStream(new File(fileName)).getCanonicalFile());

How to repeat:
- Prepare simple script using "LOAD DATA LOCAL INFILE" command
- put csv file to different path, than the application jar (e.g. application is on path "~/app.jar" and the csv file is on path "/mnt/tmp/file.csv")
- regarding the example - the application should set "user.dir" to "/mnt/tmp/"
- regarding the example - the script should reference the csv file like this: "LOAD DATA LOCAL INFILE ./file.csv" 

Suggested fix:
Resolve all files like this:
new File(fileName)).getCanonicalFile()
[25 Jun 2015 18:18] Filipe Silva
Hi Jakub,

Thank you for this bug report.

Verified as described.