dashbitco / nimble_csv

A simple and fast CSV parsing and dumping library for Elixir
https://hexdocs.pm/nimble_csv
772 stars 51 forks source link

Crash on Unexpected Escape Character #31

Closed xanderdunn closed 6 years ago

xanderdunn commented 6 years ago

I am getting this error from Nimble CSV when it attempts to parse a CSV:

Elixir.NimbleCSV.ParseError: unexpected escape character " in <<80, 75, 3, 4, 20, 0, 6, 0, 8, 0, 0, 0, 33, 0, 124, 108, 152, 22, 108, 1, 0, 0, 160, 5, 0, 0, 19, 0, 8, 2, 91, 67, 111, 110, 116, 101, 110, 116, 95, 84, 121, 112, 101, 115, 93, 46, 120, 109, 108, 32, ...>>
  File "lib/nimble_csv.ex", line 271, in NimbleCSV.RFC4180.separator/5
  File "lib/nimble_csv.ex", line 229, in anonymous fn/4 in NimbleCSV.RFC4180.parse_enumerable/2
  File "lib/enum.ex", line 1025, in anonymous fn/3 in Enum.flat_map_reduce/3
  File "lib/stream.ex", line 1384, in Stream.do_unfold/4
  File "lib/enum.ex", line 1023, in Enum.flat_map_reduce/3
  File "lib/nimble_csv.ex", line 176, in NimbleCSV.RFC4180.parse_enumerable/2
  File "lib/models/submission.ex", line 237, in APITournament.Models.Submission.create_resolver/2
  File "lib/absinthe/resolution.ex", line 184, in Absinthe.Resolution.call/2
josevalim commented 6 years ago

Can you please provide a minimal CSV that reproduces the error?

Given there are many null bytes in your string... maybe it is not encoded in UTF-8?

xanderdunn commented 6 years ago

Attached are two files that cause this exception. It looks like one of them is actually a misnamed XML binary file. The other one is a malformed CSV. We should catch these cases prior to attempting to parse them with NimbleCSV.

csvs.zip

josevalim commented 6 years ago

You don't need to handle those before, just keep in mind that you may get parsing errors in such cases. :)