Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
None
Description
The code that handles read LOCAL INFILE files does not have an error event handler on the readable stream for the file. If there's a read error while reading the file then the node process will crash as that's the default behavior for event emitter without error handlers.
There's also a race condition between checking for read access and actually opening the file for reading. If the permissions of the file change in between then the read stream will error out.
I put together a dummy test to simulate this behavior by mocking the fs.createReadStream(...) to replace the requested file with a non-existent one so that the access check passes but the read fails. As expected the node process crashes. (See https://travis-ci.org/sehrope/mariadb-connector-nodejs/jobs/537201949#L1232-L1322 for test results of this)
It's likely nobody ran into this till now as the access check / read pattern would work in most situations (it's a rare race condition) and unless a hardware disk I/O error occurs the overall read action will succeed as well.
Adding an error handler to the read stream should handle the file not existing, not being accessible to the current process, and any read errors that happen along the way.