After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 721196 - CSV. Cannot import lines with empty fields for deposit or withdrawal in bank transaction download
CSV. Cannot import lines with empty fields for deposit or withdrawal in bank ...
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Import - CSV
git-maint
Other All
: Normal normal
: ---
Assigned To: gnucash-import-maint
gnucash-import-maint
: 725846 726145 742023 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-12-29 12:52 UTC by Mike Evans
Modified: 2018-06-29 23:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Sets field to 0.0 when field is empty (846 bytes, patch)
2013-12-29 12:54 UTC, Mike Evans
needs-work Details | Review
Updated patch (880 bytes, patch)
2014-02-19 15:37 UTC, Mike Evans
committed Details | Review

Description Mike Evans 2013-12-29 12:52:08 UTC
Some CSV files downloaded from banks have empty fields for withdrawal or deposit instead of "0.0".  The importer cannot understand lines where this is the case, ie all of them.  Empty fields should probably be interpreted as 0.0 .
Comment 1 Mike Evans 2013-12-29 12:54:28 UTC
Created attachment 264994 [details] [review]
Sets field to 0.0 when field is empty

Only apples for withdrawal, deposit or balance fields.
Comment 2 Geert Janssens 2014-02-18 21:30:10 UTC
Comment on attachment 264994 [details] [review]
Sets field to 0.0 when field is empty

I wonder if this operation doesn't risk memory corruption.

Here's my reasoning:
- Assuming str is effectively ""
- That would mean it only occupies one byte of memory (the \0 termination character)

- g_strdup will allocate a new string of one byte long as well for str_dupe.

- strcmp detects the zero-length string so
- g_stpcpy is called to copy a for byte long string "0.0" into the 1 byte long buffer.

That's 3 bytes too much unless g_stpcpy also allocates memory. But I couldn't deduce that from its description [1].

IMO to be on the safe side you should use another g_strdup inside the if clause. Of course that does allocate memory so you need to g_free str_dupe before g_strdup'ing "0.0" into it.

[1] https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-stpcpy
Comment 3 Mike Evans 2014-02-19 15:37:41 UTC
Created attachment 269695 [details] [review]
Updated patch

You're right.  New patch.
Comment 4 Mike Evans 2014-03-07 10:06:24 UTC
*** Bug 725846 has been marked as a duplicate of this bug. ***
Comment 5 Mike Evans 2014-03-12 08:51:06 UTC
*** Bug 726145 has been marked as a duplicate of this bug. ***
Comment 6 Julian 2014-03-13 01:52:15 UTC
It would be good to mark the version of GNUCash this refers to - I'm thinking this must be from 2.6.1 isn't it? Would save me reporting a duplicate bug..
Comment 7 Mike Evans 2014-03-16 11:04:23 UTC
Committed patch to master 67d90c9...  Please test.
Comment 8 Mike Evans 2014-04-03 08:02:08 UTC
Since there's been no further reports I'll assume all is well and close this bug.
Comment 9 Mike Evans 2015-01-11 13:32:54 UTC
*** Bug 742023 has been marked as a duplicate of this bug. ***
Comment 10 Mike Evans 2015-01-11 13:34:16 UTC
Bug 742023 has been marked a duplicate of this of this bug and reopening this bug and updating the version.

Pasted from bug 742023:

example csv, 

Date;Description;in;out
2014-12-05;ATM withdrawal;500,00;;
2014-12-04;Expense;240;; <---no zero amount

In this case i have to edit the file and add 0,00, as the importer will fail as
it "does not understand the column field "out" or "in", depending on which is
blank.
Comment 11 Mike Evans 2015-01-11 15:55:49 UTC
It seems I forgot that some locales use a comma for decimal separator.  

Pushed to maint branch.
Comment 12 Mike Evans 2015-01-25 11:18:50 UTC
This really needs a regex to ascertain if the field contains a valid numeric value.

Committed to maint, 5e60a234006ef
Comment 13 Geert Janssens 2015-01-29 17:01:36 UTC
Comment on attachment 269695 [details] [review]
Updated patch

As far as I can see this patch has been committed to both maint and master. Just marking it as such to remove it from the unreviewed patches list in bugzilla.
Comment 14 John Ralls 2018-06-29 23:23:03 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=721196. Please update any external references or bookmarks.