Bug #60987 LOAD DATA LOCAL INFILE can path parse relative paths "higher" than 3 levels
Submitted: 27 Apr 2011 15:54 Modified: 16 Jun 2011 19:39
Reporter: Leandro Morgado Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version:5.5 OS:Any (Windows Vista, CentOS 5 Linux)
Assigned to: CPU Architecture:Any

[27 Apr 2011 15:54] Leandro Morgado
Description:
In 5.5 series, when trying to LOAD DATA LOCAL INFILE using a relative path with 3 or more levels up in the directory hierarchy, mysqld wrongly parses the path and as a consequence, can't find the file. This can cause automated script to break for example. Worse then the LOAD DATA failing would be to load the wrong data file due to a wrongly parsed (but existing) path.

How to repeat:
In my test case below I use a City.sql file that contains tab separated data from the "world" sample database, exported using regular SELECT INTO OUTFILE method. You can use any data file you wish as long as LOAD DATA LOCAL INFILE can import it.

Note, both client and server have local-infile=1 :

[mysql]
local-infile=1
...
[mysqld]
local-infile=1

TEST CASE
=========

[user@hostname 1]$ pwd
/home/user/sandboxes/msb_5_5_11/TEST/1
[user@hostname 1]$ find
.
./2
./2/3
./2/3/4
./2/3/4/City.sql

---

[user@hostname msb_5_5_11]$ /home/user/sandboxes/msb_5_5_11/use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.11-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)
...
mysql [localhost] {msandbox} (test) > TRUNCATE TABLE City; LOAD DATA LOCAL INFILE './City.sql' INTO TABLE City;
Query OK, 0 rows affected (0.00 sec)

Query OK, 4079 rows affected (0.01 sec)
Records: 4079  Deleted: 0  Skipped: 0  Warnings: 0

---

[user@hostname 4]$ mv City.sql ..
[user@hostname 4]$ /home/user/sandboxes/msb_5_5_11/use test

mysql [localhost] {msandbox} (test) > TRUNCATE TABLE City; LOAD DATA LOCAL INFILE '../City.sql' INTO TABLE City;
Query OK, 0 rows affected (0.00 sec)

Query OK, 4079 rows affected (0.01 sec)
Records: 4079  Deleted: 0  Skipped: 0  Warnings: 0

---

[user@hostname 4]$ mv ../City.sql ../../
[user@hostname 4]$ /home/user/sandboxes/msb_5_5_11/use test

mysql [localhost] {msandbox} (test) > TRUNCATE TABLE City; LOAD DATA LOCAL INFILE '../../City.sql' INTO TABLE City;
Query OK, 0 rows affected (0.00 sec)

Query OK, 4079 rows affected (0.02 sec)
Records: 4079  Deleted: 0  Skipped: 0  Warnings: 0

---

[user@hostname 4]$ mv ../../City.sql ../../../
[user@hostname 4]$ /home/user/sandboxes/msb_5_5_11/use test

mysql [localhost] {msandbox} (test) > TRUNCATE TABLE City; LOAD DATA LOCAL INFILE '../../../City.sql' INTO TABLE City;
Query OK, 0 rows affected (0.00 sec)

ERROR 2 (HY000): File '../City.sql' not found (Errcode: 2)

NOTE how above^^^ the '../../../City.sql' path is wrongly parsed as '../City.sql'! This is the bug. 

Suggested fix:
Correctly parse the relative path.
[16 Jun 2011 19:39] Paul DuBois
Noted in 5.5.15, 5.6.3 changelogs.

LOAD DATA INFILE incorrectly parsed relative data file path names
that ascended more than three levels in the file system and as a
consequence was unable to find the file. 

CHANGESET - http://lists.mysql.com/commits/139222