Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-10460

Issue insert in Postgres fails if message contains character null (0x00)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 7.1
    • Fix Version/s: 7.2
    • Component/s: Compute Engine, Database, Issues
    • Labels:
      None

      Description

      The following error occurred on SonarCloud (see INFRA-1975 for details):

      2018.02.23 14:54:28 ERROR ce[AWHC7k0xm6Cp4If4XA4N][o.s.c.t.CeWorkerImpl] Failed to execute task AWHC7k0xm6Cp4If4XA4N
      org.apache.ibatis.exceptions.PersistenceException: 
      ### Error committing transaction.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.sonar.db.issue.IssueMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Batch entry 132 INSERT INTO issues (kee, rule_id, severity, manual_severity,
          message, line, locations, gap, effort, status, tags,
          resolution, checksum, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date,
          issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type)
          VALUES ('AWHC7qYQ5rdy4n3vAwT1', 5226,
          'MINOR',
          'FALSE', 'Rename this field "lockersRename this field "lockers^@ravelCosts" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.', 28,
          ?,
          NULL, 2, 'OPEN',
          'convention', NULL, '237c7a55bb6b3ae30e198758d0234a24',
          NULL, 'arseniums@gmail.com',
          '',
          1425305152000,1519393290000, NULL,
          1519394066826, 1519394066826,
          'AWHC7ntL5rdy4n3vAuW_', 'AWHC7kurm6Cp4If4XA4H', 1) was aborted: ERROR: invalid byte sequence for encoding "UTF8": 0x00  Call getNextException to see other errors in the batch.
      ### Cause: org.apache.ibatis.executor.BatchExecutorException: org.sonar.db.issue.IssueMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: Batch entry 132 INSERT INTO issues (kee, rule_id, severity, manual_severity,
          message, line, locations, gap, effort, status, tags,
          resolution, checksum, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date,
          issue_close_date, created_at, updated_at, component_uuid, project_uuid, issue_type)
          VALUES ('AWHC7qYQ5rdy4n3vAwT1', 5226,
          'MINOR',
          'FALSE', 'Rename this field "lockersRename this field "lockers^@ravelCosts" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.', 28,
          ?,
          NULL, 2, 'OPEN',
          'convention', NULL, '237c7a55bb6b3ae30e198758d0234a24',
          NULL, 'arseniums@gmail.com',
          '',
          1425305152000,1519393290000, NULL,
          1519394066826, 1519394066826,
          'AWHC7ntL5rdy4n3vAuW_', 'AWHC7kurm6Cp4If4XA4H', 1) was aborted: ERROR: invalid byte sequence for encoding "UTF8": 0x00  Call getNextException to see other errors in the batch.
      

      This error is caused by the issue message containing the null character (0x00), introduced in it by the copy a piece of code into the issue message (presumably the name of the field with incorrect naming, but here, it seems the parsing is buggy).

      While the null character is a valid UTF8 character, it is not supported by Postgres as the server is written in C, the null character is the string delimiter (see https://www.postgresql.org/message-id/alpine.BSO.2.00.0906031639270.2432%40leary.csoft.net).

      Various courses of actions are possible to fix this bug (some could be combined):

      • remove null character from issue message before inserting it into DB
      • remove null character from issue message when passed to the Plugin API
      • remove null character from any string message for INSERT and UPDATE statement on Postgres (eg. through MyBatis or a contribution to the JDBC driver)
      • ...

      This error is not very likely to occur as it requires

      1. to have null characters in source code
      2. to have a piece of source code containing this null character to be used to build an issue message

        Attachments

          Activity

            People

            • Assignee:
              guillaume.jambet Guillaume Jambet (Inactive)
              Reporter:
              sebastien.lesaint Sebastien Lesaint
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved: