ALL: various Stream::seek(SEEK_END impls differs from docs
|Reported by:||SF/tobigun||Owned by:||fingolfin|
MemoryReadStream::seek() does not calculate the offset correctly if whence is set to SEEK_END. It calculates the offset as
offs = _size - offs;
what is wrong as the offs parameter is already negative (as it is relative to the end) and so the offset is added, resulting in an offset > eof.
The correct calculation should be
offs = _size + offs;
Same applies to SeekableSubReadStream::seek().
These bugs cause crashes if a GZipReadStream is wrapped around a memory-stream as the gzip-constructor seeks backwards from the end (seek(-4, SEEK_END)). StdioStream::seek() (normally used in conjunction with GZipReadStream) which relies on fseek() handles SEEK_END correctly.
Ticket imported from: #2664460. Ticket imported from: bugs/4209.
Change History (6)
comment:2 by , 12 years ago
|Priority:||normal → high|
|Summary:||Wrong offset calculation for memory-streams with SEEK_END → ALL: various Stream::seek(SEEK_END impls differs from docs|