Modify

Opened 12 years ago

Closed 10 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

Attachments (0)

Change History (4)

comment:1 Changed 11 years ago by gmsb

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 Changed 10 years ago by Daryle Walker

Component: Noneiostreams
Severity: Problem

comment:3 Changed 10 years ago by Frank Birbacher

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

comment:4 Changed 10 years ago by Jonathan Turkanis

Resolution: Nonefixed
Status: assignedclosed

Both problems are fixed in [42266]

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonathan Turkanis.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.