--- M:\boost-dev\boost\iostreams\detail\restrict_impl.hpp 2011-02-17 17:52:17.000000000 +0200 +++ M:\boost-dev\boost\iostreams\detail\restrict_impl_2.hpp 2012-04-27 19:21:35.000000000 +0200 @@ -141,16 +141,23 @@ template std::streamsize read(Source& src, char_type* s, std::streamsize n) { using namespace std; if (!open_) open(src, BOOST_IOS::in); - std::streamsize amt = - end_ != -1 ? - (std::min) (n, static_cast(end_ - pos_)) : - n; + + std::streamsize amt(n); + + if (end_ != -1) + { + boost::iostreams::stream_offset remaining(end_ - pos_); + + if (remaining <= std::numeric_limits::max()) + amt = (std::min)(n, static_cast(remaining)); + } + std::streamsize result = iostreams::read(this->component(), src, s, amt); if (result != -1) pos_ += result; return result; }