Uploaded image for project: 'MariaDB Connector/node.js'
  1. MariaDB Connector/node.js
  2. CONJS-79

Read errors while processing LOCAL INFILE causes process crash

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1.0
    • Component/s: other
    • 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.

        Attachments

          Activity

            People

            • Assignee:
              diego dupin Diego Dupin
              Reporter:
              sehrope Sehrope Sarkuni
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: