GNOME Bugzilla – Bug 564102
_wrap_g_output_stream_write_async not adding a reference to the buffer passed
Last modified: 2008-12-21 15:43:24 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:
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?
Created attachment 124586 [details] [review] fix for gio.OutputStream.write_async and gio.File.replace_contents_async
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 on attachment 124586 [details] [review] fix for gio.OutputStream.write_async and gio.File.replace_contents_async looks good
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().