infused / dbf

DBF is a small, fast Ruby library for reading dBase, xBase, Clipper, and FoxPro database files.
http://rdoc.info/projects/infused/dbf
MIT License
262 stars 88 forks source link

Column name cannot be empty (DBF::Column::NameError) #96

Closed gabriel-curtino closed 2 years ago

gabriel-curtino commented 2 years ago

Hi!

I got this error with a file type (04) dBase IV without memo file. Maybe related to #95.

Using ruby 2.7.4, 3.0.3 and 3.1.2. Always with dbf 4.2.0.

Type: (04) dBase IV without memo file
Memo File: false
Records: 0

Fields:
Name             Type       Length     Decimal
------------------------------------------------------------------------------
/home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/column.rb:116:in `validate_name': column name cannot be empty (DBF::Column::NameError)
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/column.rb:47:in `initialize'
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/table.rb:230:in `new'
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/table.rb:230:in `block (2 levels) in build_columns'
        from <internal:kernel>:90:in `tap'
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/table.rb:219:in `block in build_columns'
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/table.rb:314:in `safe_seek'
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/table.rb:217:in `build_columns'
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/lib/dbf/table.rb:112:in `columns'
        from /home/gahia/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dbf-4.2.0/bin/dbf:50:in `<top (required)>'
        from /home/gahia/.rbenv/versions/3.1.2/bin/dbf:25:in `load'
        from /home/gahia/.rbenv/versions/3.1.2/bin/dbf:25:in `<main>'
gabriel-curtino commented 2 years ago

I can send you some of these files but cannot attach them here...

infused commented 2 years ago

Please email a copy of the dbf to me at keithm@infused.org and I will take a look.

Thank you, Keith

infused commented 2 years ago

I just released version 4.2.1, which should fix this issue. Please give it a try and let me know if it works for you.

gabriel-curtino commented 2 years ago

It seems the new realease reads the headers properly but I'm not sure about the content.

$ dbf -s ci_A.dbf

Database: ci_A.dbf       
Type: (04) dBase IV without memo file
Memo File: false         
Records: 26

Fields:                  
Name             Type       Length     Decimal
------------------------------------------------------------------------------
D1               I          4          0         
S1               C          8          0         

Reading the table without any encoding fails

require "dbf"
table = DBF::Table.new('ci_A.dbf')
table.each do |r|
  puts r.s1
end

>> "\x94" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)

Reading the table with any encoding works. I don't really know the content of this tables and if some encryption/obfuscation is being used. It might be the case as it seems String fields have non readable info. But, in the other side, Integer fields also have weird values.

require "dbf"
table = DBF::Table.new('ci_A.dbf', nil, 'cp866')
table.each do |r|
  puts r.d1.to_s + " == " + r.s1.to_s
end

>> 16777344 == Ф!╬╓ЇХ8╤
>> 33554560 == Ф"╬╓ЛХ7▄
>> 50331776 == Ф#╬╒УХ6э                                                                                  
>> 67108992 == Ф$╬╙тХ5▐ 
...
>> 26

Using this Paradox dBase Reader it shows this:

captura

This is another example:

Database: ax.dbf
Type: (04) dBase IV without memo file
Memo File: false
Records: 29871

Fields:
Name             Type       Length     Decimal
------------------------------------------------------------------------------
D1               C          6          0         
D2               I          4          0         

...

"0Z9U04","-1360976512"
"0Z9U08","-695786112"
"0Z9U08","-632150912"
"0Z9U08","1985094784"
"0Z9U08","-1360976512"
"0Z9U20","-632150912"
"0ZJK02","-366334592"
"0ZJK02","-2044056192"
"0ZJK02","573189504"
"0ZJK02","-1305793152"
"0ZJK03","-2044056192"

captura2

Thanks!