instructure/canvas-lms · error · ImportError

Some of the fields contain NULL character

Error message

Some of the fields contain NULL character

What it means

Canvas SIS CSV import validation rejects any row whose CSV field values contain a literal NUL byte ("\x00"). UserImporter.validate checks every field of the parsed row and raises ImportError before any user record is processed, because NUL bytes can corrupt downstream string handling and database writes. It is a defensive data-hygiene check on the raw CSV content.

Solutions

  1. Open the CSV in an editor/script and strip NUL bytes before import: `File.write(path, File.read(path).gsub("\x00", ''))`
  2. Re-export the source file as clean UTF-8 text without binary padding
  3. Check the producing system/export job for the bug that injects NUL padding
  4. Sanitize programmatically at parse time by mapping fields through `v.to_s.delete("\x00")` upstream of the importer

Example fix

// before
CSV.foreach(path) { |row| importer.process(row) }
// after
CSV.foreach(path) do |row|
  row = row.map { |v| v.to_s.delete("\x00") }
  importer.process(row)
end
Defensive patterns

Strategy: validation

Validate before calling

def clean_csv_row?(row)
  row.fields.all? { |v| !v.to_s.include?("\x00") }
end
raise 'NUL byte in CSV' unless clean_csv_row?(row)

Try / catch

begin
  importer.validate(row)
rescue SIS::Base::ImportError => e
  logger.warn("Skipping row: #{e.message}")
end

Prevention

When it happens

Trigger: A user CSV row (e.g. user_id, email, name columns) contains an embedded NUL byte, so `row.fields.any? { |v| v.to_s.include?("\x00") }` is true when validate(row) is called during import of lib/sis/csv/user_importer.rb.

Common situations: CSV files exported from databases or legacy systems that embed NUL characters; binary files mistakenly renamed to .csv; files produced by buggy ETL scripts writing fixed-width buffers with NUL padding; UTF-16-encoded files interpreted as UTF-8.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/4ed75fbbf29b85fb. Report an issue: GitHub.

Appendix: source

Thrown at lib/sis/csv/user_importer.rb:79

          declared_user_type: row["declared_user_type"],
          password: row["password"],
          canvas_password_notification: row["canvas_password_notification"],
          ssha_password: row["ssha_password"],
          integration_id: row["integration_id"],
          short_name: row["short_name"],
          full_name: row["full_name"],
          sortable_name: row["sortable_name"],
          home_account: row["home_account"],
          lineno: row["lineno"],
          csv:,
          row:,
          authentication_provider_id: row["authentication_provider_id"]
        )
      end

      def validate(row)
        if row.fields.any? { |v| v.to_s.include?("\x00") }
          raise ImportError, "Some of the fields contain NULL character"
        end
      end
    end
  end
end

View on GitHub (pinned to 1c9f0bb801)