Opened 12 years ago

Closed 12 years ago

#4439 closed Bugs (duplicate)

Possible infinite loop in boost:: filesystem::copy_file for unix

Reported by: Roberto Carlos Toledano Gómez <rctg82@…> Owned by: Beman Dawes
Milestone: Boost 1.44.0 Component: filesystem
Version: Boost Development Trunk Severity: Problem
Keywords: copy, filesystem Cc:

Description

In the write cycle:

do {

if ((sz = ::write(outfile, buf.get() + sz_write,

sz_read - sz_write))< 0)

{

sz_read = sz; cause read loop termination break; and error to be thrown after closes

} sz_write += sz;

} while (sz_write < sz_read);

Always try to write a number of bytes strictly greater than zero and the api ::write returns according to the official documentation :" On success, the number of bytes written is returned (Zero Indicates Nothing Was Written). On error, -1 is returned, and errno is set appropriately". Now imagine that the ::write api for any error or side effect, always returns zero, then we are in an infinite loop.

To fix it I think the appropriate condition should be:

if ((sz =
write (outfile, buf.get () + sz_write, sz_read - sz_write)) <= 0)

that is, change the Boolean operation for less than or equal to (<=)

If I'm wrong please let me know what to learn. In my opinion you are the best.

Change History (2)

comment:1 by Marshall Clow, 12 years ago

This seems like a duplicate of #4438

comment:2 by Steven Watanabe, 12 years ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.