GNOME Bugzilla – Bug 681374
g_seekable_seek() out-of-bounds behavior is inconsistent between implementations
Last modified: 2018-05-24 14:27:23 UTC
The g_seekable_seek() docs don't say what happens if you try to seek out of bounds. Implementations like GMemory*Stream return G_IO_ERROR_INVALID_ARGUMENT if the resulting offset would be greater than the length of the stream. But the GLocalFile*Stream implementations just pass the value to lseek(), meaning if the offset is too large, it will just seek past the end of the file (potentially causing it to be extended in the GLocalFileOutputStream case). g_local_file_input_stream_skip() also fails to take this behavior of lseek() into account, meaning that if you try to skip more bytes than are left in the file, you'll get a different result than if you try to read that many bytes (contradicting the g_input_stream_skip() docs). A fix for that last part is attached.
Created attachment 220552 [details] [review] gio: fix GLocalFileInputStream skip() behavior If you try to skip past the end of a stream, it's supposed to only skip up to the end of the stream. But GLocalFileInputStream was not doing this. Fix up several problems in GInputStream's default seekable-based skip() implementation, remove GLocalFileInputStream's now-unnecessary implementation, and test that it works correctly from gio/tests/readwrite.c.
Note bug 684842.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/587.