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 505330 - Gnumeric crashes on opening Excel 97 file
Gnumeric crashes on opening Excel 97 file
Status: RESOLVED FIXED
Product: Gnumeric
Classification: Applications
Component: import/export MS Excel (tm)
git master
Other All
: Normal normal
: ---
Assigned To: Morten Welinder
Jody Goldberg
Depends on:
Blocks:
 
 
Reported: 2007-12-24 00:37 UTC by Thilo
Modified: 2008-04-19 01:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the file that crashes for me. (43.50 KB, application/vnd.ms-excel)
2007-12-24 00:38 UTC, Thilo
  Details
the debug log. (2.65 KB, text/x-log)
2007-12-24 00:41 UTC, Thilo
  Details
Patch (2.56 KB, patch)
2007-12-24 01:33 UTC, Morten Welinder
needs-work Details | Review
PATCH: fixing some missing / incomplete overflow checks (1.04 KB, patch)
2008-02-02 16:23 UTC, Hans de Goede
none Details | Review

Description Thilo 2007-12-24 00:37:37 UTC
I got this. I will attach the file and the debug log.

$ gnumeric G02hist.xls 
Reading file:///home/vinci/Desktop/G02hist.xls
Excel 97 +

warning: Can't read pathname for load map: Input/output error.

warning: Can't read pathname for load map: Input/output error.
Cannot access memory at address 0xcc0f4c60
Cannot access memory at address 0xcc0f4c60

(bug-buddy:3198): Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion `g_utf8_validate (text, len, NULL)' failed
Comment 1 Thilo 2007-12-24 00:38:25 UTC
Created attachment 101525 [details]
the file that crashes for me.
Comment 2 Thilo 2007-12-24 00:41:30 UTC
Created attachment 101526 [details]
the debug log. 

hope this helps
Comment 3 Morten Welinder 2007-12-24 01:00:38 UTC
I see the problem differently:

  • #0 read_utf16_str
    at ms-excel-read.c line 4988
  • #1 excel_read_HLINK
    at ms-excel-read.c line 5072
  • #2 excel_read_sheet
    at ms-excel-read.c line 5923
  • #3 excel_read_BOF
    at ms-excel-read.c line 6162
  • #4 excel_read_workbook
    at ms-excel-read.c line 6230
  • #5 excel_file_open
    at boot.c line 191
  • #6 go_plugin_loader_module_func_file_open
    at go-plugin-loader-module.c line 239
  • #7 go_plugin_file_opener_open
    at go-plugin-service.c line 476

Comment 4 Morten Welinder 2007-12-24 01:33:02 UTC
Created attachment 101528 [details] [review]
Patch

Our sanity checks needed a little update.  With the attached patch I get...

(lt-gnumeric:3127): gnumeric:read-WARNING **: File is most likely corrupted.
(Requested 2045430240 items of size 2, but only 144 bytes left in record.
The problem occurred in excel_read_HLINK.

and the file loads.
Comment 5 Morten Welinder 2007-12-24 01:33:37 UTC
Patch needs review for 1.8.1
Comment 6 Jody Goldberg 2007-12-29 21:30:02 UTC
Rather than a macro, we can make it a function, and pass in some context so that we can generate decent warnings.
Comment 7 Morten Welinder 2008-01-05 02:26:09 UTC
We could make it a macro, but we would have to pass in more that just
context.  We would need the number of bytes left too.
Comment 8 Morten Welinder 2008-01-16 03:36:54 UTC
I made as much of it as possible a function, but I did not bother changing
the error message at this point.

This problem has been fixed in our software repository. The fix will go into the next software release. Thank you for your bug report.

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
Comment 9 Hans de Goede 2008-02-02 16:23:34 UTC
Created attachment 104258 [details] [review]
PATCH: fixing some missing / incomplete overflow checks

Hi,

Short intro I'm the Fedora gnumeric package maintainer.

While reviewing the patch for this currently in svn, I noticed that one check (in both the old and new form) was checking for less bytes then actually used.

Up on further inspection I also found 2 missing checks, where read_utf16_str() got called without first checking if that many bytes were in the buffer.

This patch fixes both these issues.

Regards,

Hans
Comment 10 Morten Welinder 2008-02-02 17:24:48 UTC
Fixed, thanks.  Note, that you cannot do things like

    XL_NEED_BYTES (len + 16 + 12 + 4);

because the addition might overflow.

Btw., the past week has seen a *pile* of fixes for this kind of issues.

	* Fix corrupted-xls-file problems.  [#512984] [#513005] [#513313]
	  [#513317] [#513361] [#513364] [#513551] [#513605] [#513608] [#513790]
	  [#513787] [#513835]
	* Band-aid evaluation problem with broken xls.  [#513559]
Comment 11 Morten Welinder 2008-02-14 05:05:54 UTC
It appears that someone has reported this as a security bug.

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-0668

We are on the read side here.  One of these things can happen:

* The record size unexpectedly is zero.  That generally leads to a null pointer
  reference which, while irritating, does not create a security risk on any
  platform I can imagine.

* The record size is smaller than it should be, but not zero.  In this case we
  may read bytes we should not.  The result will be nonsense, but no security
  risk in sight.

This much is true for all the bug numbers listed above.  For HLINK there
is an extra issue: it might be possible to send a very large length to
read_utf16_str and have the *2 there overflow.  If so, we will be storing
string data in unpleasant places.  That indeed does smell like a security
problem.
Comment 12 J.H.M. Dassen (Ray) 2008-04-12 08:18:25 UTC
The fix for this issue has been backported to gnumeric 1.6 by the Debian
security team as Debian's stable release ("etch") includes gnumeric 1.6.
I've taken the liberty of committing it as
http://svn.gnome.org/viewvc/gnumeric?view=revision&revision=16509
Comment 13 Morten Welinder 2008-04-12 14:00:02 UTC
Great -- a volunteer for maintaining 1.6!  :-)

Seriously, most of the patch you committed is actually not security issues.
The added safety comes from the overflow checks, not from checking that the
file has enough data -- it's no big deal if we read some random bytes from
memory.
Comment 14 Kees Cook 2008-04-18 20:30:03 UTC
The patch for 1.6 has a minor error in the data counting.  The switch statement was changed to post-increment data, so the default handler should not still have "data++" in it, I think.