Open Bug 1960252 Opened 9 months ago Updated 8 months ago

nsBufferedOutputStream SetEOF() doesn't account for unwritten data in buffer

Categories

(Core :: Networking: File, defect, P2)

defect
Points:
3

Tracking

()

People

(Reporter: benc, Unassigned, NeedInfo)

References

Details

(Whiteboard: [necko-triaged][necko-priority-next])

Attachments

(1 file)

Calling SetEOF() to truncate an nsBufferedOutputStream doesn't take into account unflushed data in the buffer.

It uses nsBufferedStream::SetEOF(), which just calls SetEOF() on the underlying stream:
https://searchfox.org/comm-central/rev/b56347bd5a63f051bdc994ed4051088b37df4c99/mozilla/netwerk/base/nsBufferedStreams.cpp#246

But if there's unwritten data in the buffer, it'll get written out at the next Flush().
This is confusing because - from the callers point of view - it was written out before the SetEOF() call, and thus should have been truncated.

An xpcshell test to illustrate the issue.

It needs a buffer-aware nsBufferedOutputStream::SetEOF(). But just calling Flush() before the underlying-stream SetEOF() isn't enough. The Flush() changes the position within the file, so the SetEOF() will occur at an unexpected position (unexpected to the caller, anyway).

See Also: → 1960263
Severity: -- → S3
Priority: -- → P2
Whiteboard: [necko-triaged][necko-priority-new]
Severity: S3 → S4
Points: --- → 3
Flags: needinfo?(kershaw)
Whiteboard: [necko-triaged][necko-priority-new] → [necko-triaged][necko-priority-next]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: