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 564102 - _wrap_g_output_stream_write_async not adding a reference to the buffer passed
_wrap_g_output_stream_write_async not adding a reference to the buffer passed
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gio
2.15.x
Other All
: High critical
: ---
Assigned To: Paul Pogonyshev
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2008-12-11 11:35 UTC by Tomeu Vizoso
Modified: 2008-12-21 15:43 UTC
See Also:
GNOME target: ---
GNOME version: 2.23/2.24


Attachments
fix for gio.OutputStream.write_async and gio.File.replace_contents_async (2.09 KB, patch)
2008-12-13 14:55 UTC, Paul Pogonyshev
committed Details | Review

Description Tomeu Vizoso 2008-12-11 11:35:27 UTC
Please describe the problem:
as no ref is added, python may reuse that buffer and undefined content may be written instead.


Steps to reproduce:
Cannot be easily reproduced, as depends on the python interpreter to decide to reuse the buffer.

Actual results:


Expected results:


Does this happen every time?


Other information:
Comment 1 Paul Pogonyshev 2008-12-12 21:32:17 UTC
OK, I see what you mean.  I don't really know a lot about buffers in Python, but quick investigation suggests that there are read-write buffers supported, even if there are none in stdlib, right?  In this case we should not add a reference to the buffer, but instead copy its contents, because it might change while output is in progress.  Is this correct?  Can you find other functions with similar potential bug?
Comment 2 Paul Pogonyshev 2008-12-13 14:55:52 UTC
Created attachment 124586 [details] [review]
fix for gio.OutputStream.write_async and gio.File.replace_contents_async
Comment 3 Tomeu Vizoso 2008-12-16 10:18:54 UTC
I *think* string buffers in python can be write to, so you would be right and the buffer needs to be copied. But maybe someone more knowledgeable than me could comment.

Thanks a lot for your patch, looks quite good to me.
Comment 4 Gustavo Carneiro 2008-12-21 14:55:12 UTC
Comment on attachment 124586 [details] [review]
fix for gio.OutputStream.write_async and gio.File.replace_contents_async

looks good
Comment 5 Paul Pogonyshev 2008-12-21 15:43:24 UTC
Sending        ChangeLog
Sending        gio/gfile.override
Sending        gio/gio.override
Sending        gio/goutputstream.override
Transmitting file data ....
Committed revision 980.


2008-12-21  Paul Pogonyshev  <pogonyshev@gmx.net>

	Bug 564102 – _wrap_g_output_stream_write_async not adding a
	reference to the buffer passed

	* gio/gio.override (pygio_notify_copy_buffer): New function.
	(pygio_free_notify): Free new `buffer' field if it is set.

	* gio/goutputstream.override (_wrap_g_output_stream_write_async):
	Copy the buffer with new pygio_notify_copy_buffer() and use the
	copy for g_output_stream_write_async() call.

	* gio/gfile.override (_wrap_g_file_replace_contents_async): Same
	as for _wrap_g_output_stream_write_async().