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 312105 - [PATCH] Fix crash adding an attachment
[PATCH] Fix crash adding an attachment
Status: RESOLVED FIXED
Product: balsa
Classification: Other
Component: general
2.3.x
Other FreeBSD
: Normal critical
: ---
Assigned To: Balsa Maintainers
Balsa Maintainers
Depends on:
Blocks:
 
 
Reported: 2005-07-31 02:27 UTC by Joe Marcus Clarke
Modified: 2005-08-08 00:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix crash when adding an attachment (1.04 KB, patch)
2005-07-31 02:28 UTC, Joe Marcus Clarke
none Details | Review
proposed substitute patch (against cvs) (1.40 KB, patch)
2005-08-01 01:08 UTC, Peter Bloomfield
none Details | Review
incremental patch (1.86 KB, patch)
2005-08-01 13:31 UTC, Peter Bloomfield
none Details | Review

Description Joe Marcus Clarke 2005-07-31 02:27:05 UTC
Version details: 2.3.4
Distribution/Version: All versions

This is a bit tricky (and easy at the same time).  I'm sure it doesn't crash on
Linux, or it would have been noticed before.  However, on FreeBSD, if you add an
attachment (any attachment) to a new message, Balsa crashes in gtk_list_store_set().

The problem is that Balsa tries to fit the attachment's size into a gint. 
However, on FreeBSD, the stat.st_size member is of type off_t which is analagous
to a uint64_t.  Therefore, the attached patch stores the attachment's size as a
guint64.
Comment 1 Joe Marcus Clarke 2005-07-31 02:28:48 UTC
Created attachment 49995 [details] [review]
Fix crash when adding an attachment
Comment 2 Peter Bloomfield 2005-08-01 01:07:42 UTC
Thanks for the report!

As you note, this is tricky...with your patch, my compile fails because the
g_strdup_printf on line 2680 has a mismatch between the guint64 argument and the
%d format specifier.  I can fix it with %lld, but that works for me only because
sizeof(long long int) == sizeof(guint64).  That may not be portable.

I believe that long int (== glong) may be the largest type that has a G_TYPE_*
macro (and can therefore be specified in gtk_tree_store_new() and can be
specified in a printf format specifier ("%ld").

The following patch builds on my box--could you check it out?  It casts st_size
to (glong), so if you attached a really huge file, the size would be truncated,
but it's used only for printing, so it shouldn't be fatal.
Comment 3 Peter Bloomfield 2005-08-01 01:08:52 UTC
Created attachment 50039 [details] [review]
proposed substitute patch (against cvs)
Comment 4 Joe Marcus Clarke 2005-08-01 02:19:52 UTC
I don't know how mine worked with that printf.  I completely missed it.  You're
right that this patch will work (in that it compiles, and doesn't crash), but
you're still casting an off_t to a long on 32-bit FreeBSD.  Therefore, you will
lose some precision (though anyone attaching a file > 2 GB should be shot).  But
as you say, this is only for printing purposes.

Oh, and I was mistaken before.  An off_t is an int64_t not a uint64_t.  I
misread sys/types.h.  And G_TYPE_* does support the INT64 type, but I agree that
%lld is not portable.  That's why FreeBSD 5.X and higher offers %zd.

I think your new patch is the way to go.
Comment 5 Peter Bloomfield 2005-08-01 02:25:30 UTC
Thanks for testing it!  Yes, a >2GB attachment would be unthinkable with current
pathways, so there's no substantive issue.  I'm sure we'll have a portable way
to handle this before it matters!  I'll commit to cvs.

Peter
Comment 6 Peter Bloomfield 2005-08-01 13:31:34 UTC
Created attachment 50065 [details] [review]
incremental patch

Here's a better fix: use a float to store st_size in the tree-list, and cast it
to (int) when we know it's small.  Also plugs a memory leak.

This patch requires the previous one, which is already in cvs.
Comment 7 Peter Bloomfield 2005-08-08 00:49:46 UTC
Resolving as FIXED--feel free to reopen if you find any remaining problems.