[ scummvm-Patches-2664460 ] Wrong offset calculation for memory-streams with SEEK_END

SourceForge.net noreply at sourceforge.net
Thu Mar 5 09:52:33 CET 2009


Patches item #2664460, was opened at 2009-03-05 09:52
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=418822&aid=2664460&group_id=37116

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: tobigun (tobigun)
Assigned to: Nobody/Anonymous (nobody)
Summary: Wrong offset calculation for memory-streams with SEEK_END

Initial Comment:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=418822&aid=2664460&group_id=37116




More information about the Scummvm-tracker mailing list