Project

General

Profile

Actions

Bug #10223

closed

Stack level too deep in CSV when parsing long line

Added by apohllo (Aleksander Pohl) over 10 years ago. Updated about 10 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux], ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
[ruby-core:64931]

Description

The following code:

#!/usr/bin/env ruby                                                                                                                                                        
# encoding: utf-8

require 'bundler/setup'
require 'csv'

CSV.open("csv_error.csv") do |input|
  input.each do |category,*mappings|
    # do nothing
  end
end

with the data file attached causes the follwing error:

/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/csv.rb:1768: stack level too deep (SystemStackError)

Interestingly almost the same code:

#!/usr/bin/env ruby                                                                                                                                                        
# encoding: utf-8

require 'bundler/setup'
require 'csv'

CSV.open("csv_error.csv") do |input|
  input.each do |tuple|
    # do nothing
  end
end

works fine. The error appears both in Ruby 1.9.2 (ancient) and Ruby 2.1.2. So I suppose it is an error inside CSV lib.

This might be important for any developer parsing CSV files comming from the outside world, since it may cause DOS error.


Files

csv_error.csv (2.1 MB) csv_error.csv apohllo (Aleksander Pohl), 09/10/2014 02:17 PM

Updated by apohllo (Aleksander Pohl) over 10 years ago

I guess, that CSV has not much to do with that error. Probably the root cause is that *mappings inside

|category,*mappings|

is a very long array, which is (de)composed recursively. And this causes the Stack-level to deep problem.

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

  • Description updated (diff)
  • Priority changed from 5 to Normal
  • Target version set to 2.2.0
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

The shortest code would be:

def t;yield [0]*200000; end
t{|a,|}

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

  • Status changed from Open to Closed

Updated by usa (Usaku NAKAMURA) about 10 years ago

How did you make Closed, nobu?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0