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 776990 - Various miscellaneous fixes
Various miscellaneous fixes
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gdk-pixbuf-maint
gdk-pixbuf-maint
Depends on:
Blocks:
 
 
Reported: 2017-01-07 17:39 UTC by Philip Withnall
Modified: 2017-02-17 11:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
io-ico: Fix option parsing to be locale-independent (3.19 KB, patch)
2017-01-07 17:40 UTC, Philip Withnall
committed Details | Review
io-xpm: Handle fseek() failure (881 bytes, patch)
2017-01-07 17:40 UTC, Philip Withnall
committed Details | Review
thumbnailer: Add some assertions to help Coverity (1.69 KB, patch)
2017-01-07 17:40 UTC, Philip Withnall
committed Details | Review
gdk-pixbuf-loader: Add a missing NULL check (1.31 KB, patch)
2017-01-07 17:40 UTC, Philip Withnall
committed Details | Review
tests: Check that pixbufs are valid before comparing them (1.21 KB, patch)
2017-02-07 11:37 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2017-01-07 17:39:57 UTC
Spotted by Coverity.
Comment 1 Philip Withnall 2017-01-07 17:40:03 UTC
Created attachment 343092 [details] [review]
io-ico: Fix option parsing to be locale-independent

sscanf() and strtol() are both locale-dependent. In addition, the return
value of sscanf() was not being checked (so it could fail without being
noticed), and there was no bounds checking being performed.

Bounds checking is now performed, although the bounds have been chosen
for conservative backwards-compatibility, and may not be the most
appropriate.

Coverity CID: 1388522
Comment 2 Philip Withnall 2017-01-07 17:40:08 UTC
Created attachment 343093 [details] [review]
io-xpm: Handle fseek() failure

If fseek() fails, the image is corrupt, and so the call to this get_buf
function should fail.

Coverity CID: 1388523
Comment 3 Philip Withnall 2017-01-07 17:40:12 UTC
Created attachment 343094 [details] [review]
thumbnailer: Add some assertions to help Coverity

From looking at the code, these assertions should always hold already,
but it clarifies the code and helps static analysis if we add them
explicitly.

(n_pixels == 0) is only true if (s_x1 == s_x2 || s_y1 == s_y2), which is
only true if (dx == 0 || dy == 0). This cannot be true, because dx and
dy are the result of dividing source_[width|height] by
dest_[width|height], and there’s already an assertion that the former
are greater or equal to the latter.

Coverity CID: 1388528
Comment 4 Philip Withnall 2017-01-07 17:40:17 UTC
Created attachment 343095 [details] [review]
gdk-pixbuf-loader: Add a missing NULL check

The code just above checks whether image_module is NULL, and it doesn’t
look like it can change in the meantime, so we should also check before
dereferencing it for load_increment.

Coverity CID: 1388529
Comment 5 Bastien Nocera 2017-02-07 10:50:14 UTC
Review of attachment 343092 [details] [review]:

::: gdk-pixbuf/io-ico.c
@@ +1239,3 @@
+ * @minimum and @maximum are valid inclusively. */
+static gboolean
+ascii_strtoll (const gchar  *str,

We have the same strtol{l,} usage in other loaders. Can you please move that to gdk-pixbuf-private.h, in a separate patch?
Comment 6 Bastien Nocera 2017-02-07 10:51:25 UTC
Review of attachment 343093 [details] [review]:

Definitely.
Comment 7 Bastien Nocera 2017-02-07 10:53:53 UTC
Review of attachment 343095 [details] [review]:

> and it doesn’t look like it can change in the meantime

I don't understand the point here. Is this just so that Coverity isn't confused? I'd add an assert(priv->image_module) instead.
Comment 8 Bastien Nocera 2017-02-07 10:56:22 UTC
Review of attachment 343094 [details] [review]:

Pushed to gnome-thumbnailer-skeleton, can you please fold this into the "Update from gnome-thumbnailer-skeleton" patch?
Comment 9 Philip Withnall 2017-02-07 11:25:58 UTC
Review of attachment 343095 [details] [review]:

> I don't understand the point here. Is this just so that Coverity isn't confused? I'd add an assert(priv->image_module) instead.

It was a toss-up between adding this non-fatal check and adding a fatal assertion. Basically, I’m not confident enough about what that code is trying to achieve to be 100% sure that priv->image_module will be set in the mean time, from somewhere. Unless you’re 100% sure that priv->image_module will always be non-NULL at that point, or we rewrite the code to be less all-over-the-place, I’d suggest a non-fatal check rather than an assertion.
Comment 10 Philip Withnall 2017-02-07 11:26:35 UTC
Review of attachment 343094 [details] [review]:

> Pushed to gnome-thumbnailer-skeleton, can you please fold this into the "Update from gnome-thumbnailer-skeleton" patch?

Oops, I’ve already pushed that one. I’ll reword the commit message on this one to be “Update from g-t-s”
Comment 11 Bastien Nocera 2017-02-07 11:28:08 UTC
(In reply to Philip Withnall from comment #9)
> Review of attachment 343095 [details] [review] [review]:
> 
> > I don't understand the point here. Is this just so that Coverity isn't confused? I'd add an assert(priv->image_module) instead.
> 
> It was a toss-up between adding this non-fatal check and adding a fatal
> assertion. Basically, I’m not confident enough about what that code is
> trying to achieve to be 100% sure that priv->image_module will be set in the
> mean time, from somewhere. Unless you’re 100% sure that priv->image_module
> will always be non-NULL at that point, or we rewrite the code to be less
> all-over-the-place, I’d suggest a non-fatal check rather than an assertion.

We're still in development. Please make it fatal, and we'll change it if we see the problem happen in actual usage.
Comment 12 Philip Withnall 2017-02-07 11:28:26 UTC
Attachment 343093 [details] pushed as 3a53fc4 - io-xpm: Handle fseek() failure
Comment 13 Philip Withnall 2017-02-07 11:30:36 UTC
(In reply to Bastien Nocera from comment #11)
> (In reply to Philip Withnall from comment #9)
> > Review of attachment 343095 [details] [review] [review] [review]:
> > 
> > > I don't understand the point here. Is this just so that Coverity isn't confused? I'd add an assert(priv->image_module) instead.
> > 
> > It was a toss-up between adding this non-fatal check and adding a fatal
> > assertion. Basically, I’m not confident enough about what that code is
> > trying to achieve to be 100% sure that priv->image_module will be set in the
> > mean time, from somewhere. Unless you’re 100% sure that priv->image_module
> > will always be non-NULL at that point, or we rewrite the code to be less
> > all-over-the-place, I’d suggest a non-fatal check rather than an assertion.
> 
> We're still in development. Please make it fatal, and we'll change it if we
> see the problem happen in actual usage.

Makes sense.
Comment 14 Philip Withnall 2017-02-07 11:36:17 UTC
Comment on attachment 343095 [details] [review]
gdk-pixbuf-loader: Add a missing NULL check

Attachment 343095 [details] pushed as 2634506 - gdk-pixbuf-loader: Add a missing NULL check
Comment 15 Philip Withnall 2017-02-07 11:37:58 UTC
Created attachment 345099 [details] [review]
tests: Check that pixbufs are valid before comparing them

Assert that the pixbufs have non-negative dimensions before comparing
them and potentially using one of the dimensions as a loop bound.

Coverity IDs: 1399711, 1399712
Comment 16 Philip Withnall 2017-02-07 12:31:43 UTC
Review of attachment 343092 [details] [review]:

::: gdk-pixbuf/io-ico.c
@@ +1239,3 @@
+ * @minimum and @maximum are valid inclusively. */
+static gboolean
+ascii_strtoll (const gchar  *str,

That sounds sensible, but actually all the other loaders already implement the necessary errno and bounds checks on their strtol() calls. In addition, there is no internal shared library for all the loaders, so in order to share this code we would either have to add it as a static inline in gdk-pixbuf-private.h, or create a new internal utils library. Since there are no bugs with this in the other loaders, that’s refactoring work, which I don’t have time to do at the moment.

So I’d suggest pushing this commit in its current form, at least for the moment.
Comment 17 Bastien Nocera 2017-02-17 10:51:31 UTC
Review of attachment 343092 [details] [review]:

Fine then.
Comment 18 Bastien Nocera 2017-02-17 10:51:57 UTC
Review of attachment 345099 [details] [review]:

Sure.
Comment 19 Philip Withnall 2017-02-17 11:41:35 UTC
Attachment 343092 [details] pushed as 91723d7 - io-ico: Fix option parsing to be locale-independent
Attachment 345099 [details] pushed as 0f53857 - tests: Check that pixbufs are valid before comparing them