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 652521 - get_length fails in Clutter.Path when length is greater than 46340
get_length fails in Clutter.Path when length is greater than 46340
Status: RESOLVED FIXED
Product: clutter
Classification: Platform
Component: general
1.10.x
Other Linux
: Normal normal
: ---
Assigned To: clutter-maint
clutter-maint
Depends on:
Blocks:
 
 
Reported: 2011-06-14 06:42 UTC by Pablo Sánchez
Modified: 2012-04-27 11:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
C reproducer (325 bytes, text/plain)
2012-04-23 15:28 UTC, Martin Pitt
  Details
path: Avoid integer overflow in get_distance() (5.51 KB, patch)
2012-04-23 16:46 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review

Description Pablo Sánchez 2011-06-14 06:42:26 UTC
I've found a small bug when creating a ClutterBehaviour object (with python bindings and Gnome Introspection)

Python bindings:

>>> import clutter
>>> knots = "M 0 0 L 46340 0"
>>> path = clutter.Path(knots)
>>> path.get_length()
46340L
>>> knots = "M 0 0 L 46341 0"
>>> path = clutter.Path(knots)
>>> path.get_length()
2147483648L

Gnome Introspection:

>>> from gi.repository import Clutter
>>> knots = "M 0 0 L 46340 0"
>>> path = Clutter.Path()
>>> path.add_string(knots)
True
>>> path.get_length()
46340L
>>> knots = "M 0 0 L 46341 0"
>>> path.add_string(knots)
True
>>> path.get_length()
2147529988L
Comment 1 Martin Pitt 2012-04-23 15:28:07 UTC
Created attachment 212611 [details]
C reproducer

This is not a bug in pygobject or the GI bindings. If you use the C API directly, you get exactly the same problem:

$ gcc -o /tmp/clutter clutter.c `pkg-config --cflags --libs clutter-1.0`
$ /tmp/clutter 
len: -2147483648
Comment 2 Emmanuele Bassi (:ebassi) 2012-04-23 16:45:52 UTC
get_length() returns an unsigned integer, not a signed long.

the distance between two points (x_a, y_a) and (x_b, y_b) is:

  sqrt ((x_b - x_a) * (x_b - x_a) + (y_b - y_a) * (y_b - y_a))

which, for (0, 0) - (46341, 0) resolves as

  sqrt (46341 * 46341)

which overflows the integer range. then, the whole issue gets hidden by the fact that get_distance() returns an unsigned integer (ugh) value.

the whole ClutterPath is a mess - but the only way to actually fix it is to break API and move to floating point everywhere.
Comment 3 Emmanuele Bassi (:ebassi) 2012-04-23 16:46:27 UTC
Created attachment 212620 [details] [review]
path: Avoid integer overflow in get_distance()

This should fix the overflow; I added a test case to the conformance test suite as well.
Comment 4 Emmanuele Bassi (:ebassi) 2012-04-27 11:40:46 UTC
Attachment 212620 [details] pushed to master as commit 0fca11ec