Opened 17 years ago

Closed 15 years ago

#586 closed Patches (fixed)

iostreams // file_descriptor::seek BUG on files > 4 GB

Reported by: nobody Owned by: Jonathan Turkanis
Milestone: Component: iostreams
Version: None Severity: Problem
Keywords: Cc:

Description

Boost 1.33.1
iostreams library
file_descriptor::seek() method
file_descriptor.cpp, line 198
Win32, Visual C++ 2005

The method seek() can return a wrong value of a newly 
set offset when the offset is further than 4 GB.

//---------------
return offset_to_position((lDistanceToMoveHigh << 32) 
+ dwResultLow);
//---------------

The code above has a bug. On 32-bit systems the 
expression (lDistanceToMoveHigh << 32) equals to 
lDistanceToMoveHigh.

The correct code should first cast the 
lDistanceToMoveHigh variable to 64-bit and then shift 
it.

//---------------
return (static_cast<boost::intmax_t> 
lDistanceToMoveHigh) << 32) + dwResultLow;
//---------------


Sergey Kolodkin

Change History (4)

comment:1 by gmsb, 16 years ago

Logged In: YES 
user_id=271167
Originator: NO

There's also a bug 3 lines earlier. Windows GetLastError() shouldn't be checked unless dwResultLow is INVALID_SET_FILE_POINTER.

Replace:

  195   if (::GetLastError() != NO_ERROR) {
  196             throw detail::bad_seek();
  197         } else {
  198            return offset_to_position((lDistanceToMoveHigh << 32) + dwResultLow);
  199         }
  200     }

With:

  195   if (INVALID_SET_FILE_POINTER == dwResultLow && ::GetLastError() != NO_ERROR) {
  196             throw detail::bad_seek();
  197         } else {
  198            return offset_to_position((static_cast<stream_offset>(lDistanceToMoveHigh) << 32) + dwResultLow);
  199         }
  200     }


comment:2 by Daryle Walker, 15 years ago

Component: Noneiostreams
Severity: Problem

comment:3 by Frank Birbacher, 15 years ago

Bug noted and addressed in [38880]. Still needs approval of maintainer.

comment:4 by Jonathan Turkanis, 15 years ago

Resolution: Nonefixed
Status: assignedclosed

Both problems are fixed in [42266]

Note: See TracTickets for help on using tickets.