1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-09-13 02:57:35 +00:00

AK: Allow reading from EOF buffered streams better in read_line()

If the BufferedStream is able to fill its entire circular buffer in
populate_read_buffer() and is later asked to read a line or read until
a delimiter, it could erroneously return EMSGSIZE if the caller's buffer
was smaller than the internal buffer. In this case, all we really care
about is whether the caller's buffer is big enough for however much data
we're going to copy into it. Which needs to take into account the
candidate.
This commit is contained in:
Andrew Kaster 2024-02-21 19:42:27 -07:00 committed by Andrew Kaster
parent 0a55749a39
commit 21ac431fac
2 changed files with 30 additions and 1 deletions

View file

@ -87,7 +87,8 @@ public:
auto const candidate = TRY(find_and_populate_until_any_of(candidates, buffer.size()));
if (stream().is_eof()) {
if (buffer.size() < m_buffer.used_space()) {
if ((candidate.has_value() && candidate->offset + candidate->size > buffer.size())
|| (!candidate.has_value() && buffer.size() < m_buffer.used_space())) {
// Normally, reading from an EOFed stream and receiving bytes
// would mean that the stream is no longer EOF. However, it's
// possible with a buffered stream that the user is able to read