tmontaigu / dbase-rs

Rust library to read & write dBase files.
MIT License
29 stars 30 forks source link

ParseFloatError when reading a Numeric value due to nul byte padding #16

Closed GtrMo closed 3 years ago

GtrMo commented 3 years ago

When I tried to read the dbf file provided by the french land registry, I encountered a ParseFloatError on a Numeric field. Any 'parcelles' shapefile available should reproduce this error.

I was able to narrow it down to the fact that when a Numeric field is a string padded with NUL bytes, the value.trim() call in field.rs:286 does not work (see playground).

This behavior is normal for Rust, but results in a ParseFloatError in dbase-rs.

Other dbf libraries do not seem to have this issue. This bug can be resolved by replacing the nul bytes by spaces, as pyshp does.

Should I open a PR ? If so, do you prefer to modify the read_string_of_len function, or should I create another one to read numeric strings ?

Note: this bug is likely to also happen with the Float field type, but I haven't tested it.

tmontaigu commented 3 years ago

I think the best is to modify the read_string_of_len to trim null bytes out of the vec or replace null bytes with spaces as you suggested