[CONJS-79] Read errors while processing LOCAL INFILE causes process crash Created: 2019-05-25  Updated: 2019-06-18  Resolved: 2019-05-28

Status: Closed
Project: MariaDB Connector/node.js
Component/s: other
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Bug Priority: Major
Reporter: Sehrope Sarkuni Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: 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.



 Comments   
Comment by Diego Dupin [ 2019-05-28 ]

Right, no need for double check, and better to ensure using stream callback.
(https://github.com/MariaDB/mariadb-connector-nodejs/pull/56)

Generated at Thu Feb 08 03:22:36 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.