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 720080 - Truncating a GMemoryOutputStream to a larger size causes get_data_size() to be incorrect
Truncating a GMemoryOutputStream to a larger size causes get_data_size() to b...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.39.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-12-08 20:29 UTC by Ross Lagerwall
Modified: 2013-12-15 23:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio: Update GMemoryOutputStream length after truncate (1.40 KB, patch)
2013-12-08 20:43 UTC, Ross Lagerwall
committed Details | Review

Description Ross Lagerwall 2013-12-08 20:29:22 UTC
As per the bug description.

This came up when working on bug 720062.
Comment 1 Ross Lagerwall 2013-12-08 20:43:15 UTC
Created attachment 263775 [details] [review]
gio: Update GMemoryOutputStream length after truncate

For GMemoryOutputStream, update valid_len when truncating so that
g_memory_output_stream_get_data_size () returns the correct result.
Comment 2 Matthias Clasen 2013-12-15 15:44:50 UTC
Review of attachment 263775 [details] [review]:

::: gio/tests/memory-output-stream.c
@@ +55,3 @@
+  g_seekable_truncate (G_SEEKABLE (mo), 8192, NULL, &error);
+  g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 8192);
+

Do we guarantee that the extra data reads as zeros ? If yes, would be good to test that too.
Comment 3 Allison Karlitskaya (desrt) 2013-12-15 19:17:47 UTC
See bug 684842 about recent activity here.

Particularly, be careful about the fixed-sized case.  It looks like array_resize() will error out in that case anyway, so I think this is probably fine.

As for reading extra zero bytes in the non-fixed-sized case, I think that would indeed be consistent with the view of a seekable non-fixed-size output stream behaving similarly to a file.  Probably worth putting under a test.
Comment 4 Matthias Clasen 2013-12-15 23:51:20 UTC
Attachment 263775 [details] pushed as 3b9ad6e - gio: Update GMemoryOutputStream length after truncate