Bug 26557 - Incorrect behavior with open_memstream in recent version(s) of glibc
Summary: Incorrect behavior with open_memstream in recent version(s) of glibc
Status: UNCONFIRMED
Alias: None
Product: glibc
Classification: Unclassified
Component: stdio (show other bugs)
Version: 2.28
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-31 20:31 UTC by Tom Truscott
Modified: 2022-06-06 16:16 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
memstream-test.c (522 bytes, text/plain)
2020-08-31 20:31 UTC, Tom Truscott
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Truscott 2020-08-31 20:31:52 UTC
Created attachment 12812 [details]
memstream-test.c

The attached memstream-test.c gives expected fseek() behavior on streams created with fopen() and with fmemopen(), and also with open_memstream in glibc 2.12 and 2.17.  But in glibc 2.28 an open_memstream() gives incorrect behavior
Comment 1 Tom Truscott 2020-09-01 12:03:56 UTC
Correction: open_memstream() gives incorrect behavior in all those glibc (2.12, 2.17, 2.28, and also 2.31). The incorrect behavior varies.

Also, fmemopen() gave incorrect behavior in older glibc, but it seems okay now and our only concern is with open_memstream().
Comment 2 pipcet 2021-03-05 15:24:53 UTC
I'm seeing this as well, I believe:

When the FILE *returned by open_memstream is closed, the buffer that is returned is truncated to be as large as the current file offset, not the length of the data that has been written (and also not the actual size of the buffer that has been allocated).

Furthermore, fseek (file, 0, SEEK_END) does not seek to the end of the written buffer.

It's possible this behavior is documented in the standard, but it's not documented in the manpage.
Comment 3 Carlos O'Donell 2022-06-06 16:16:48 UTC
We started an RFC in 20220 about open_memstream behaviour to harmonize:
https://www.openwall.com/lists/libc-coord/2020/09/24/1

There is an Austin Group ticket open for clarification:
https://www.austingroupbugs.net/view.php?id=1406