Opened 7 years ago

Last modified 4 years ago

#11914 new Bugs

abort is called while boost::filesystem::copy tries to throw and exception

Reported by: jpo38 <jean.porcherot@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.65.0 Severity: Problem
Keywords: Cc: jean.porcherot@…

Description

Im" using boost 1.60 with Visual Studio 2015 WIN64. Compiled boost simply by running:

bootstrap.bat tools/build/b2 toolset=msvc-14.0 --build-type=minimal --link=static stage

Now, I get a specific situation where abort is called while boost::filesystem::copy tries to throw an exception. Note that other boost::filesystem functions successfully throws.

This code:

#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>

#include <iostream>

int main( int argc, char* argv[] )
{
    // Stepping to folder:

    try
    {
        boost::filesystem::current_path("B:/dev/msvc2015/vobs_bci/public/tst/base/cppunit/utlfile");
        std::cout << "Worked" << std::endl; // works OK
    }
    catch (...)
    {

    }

    // test throwing upon copy_directory because dource folder does not exist:

    try
    {
        boost::filesystem::copy_directory("s", "b");
    }
    catch (...)
    {
        std::cout << "Caught" << std::endl; // works OK
    }

    // test throwing upon copy because target file already exists:

    try
    {
        boost::filesystem::copy("./test.h", "./copied.cpp"); // works
        boost::filesystem::copy("./test.h", "./copied.cpp"); // should throw and be caught
    }
    catch (...)
    {
        std::cout << "Caught" << std::endl; // never reached...
    }

    std::cout << "Done" << std::endl;

    return 0;
}

Outputs:

Worked
Caught

And then aborts...

Posted on SO first: http://stackoverflow.com/questions/34793451/why-is-boostfilesystem-aborting-instead-of-throwing-an-exception

Attachments (1)

copy_exceptions.patch (529 bytes ) - added by sudhanshu.gupta05@… 4 years ago.
Patch contains the fix for the issue.

Download all attachments as: .zip

Change History (9)

comment:1 by jpo38 <jean.porcherot@…>, 7 years ago

Problem is that code ends up throwing an exception from a noexpt function!

The version of copy_directory the code posted reaches does not have BOOST_NOEXCEPT flag (line 532 of boost.org/doc/libs/1_60_0/boost/filesystem/operations.hpp), while the version of copy_file reached has it (line 548).

comment:2 by viboes, 7 years ago

Component: Nonefilesystem
Owner: set to Beman Dawes

comment:3 by jpo38 <jean.porcherot@…>, 5 years ago

I am unable to reproduce this bug with boost 1.65.1

comment:4 by jpo38 <jean.porcherot@…>, 5 years ago

My mistake, I can still reproduce this with 1.65.1. The problem was not fixed yet

comment:5 by jpo38 <jean.porcherot@…>, 5 years ago

Version: Boost 1.60.0Boost 1.65.0

comment:6 by jpo38 <jean.porcherot@…>, 5 years ago

Cc: jean.porcherot@… added

comment:7 by anonymous, 5 years ago

Why isn't this set to showstopper? How is the current behavior in any way acceptable?

comment:8 by sudhanshu.gupta05@…, 4 years ago

The problem here is that implementation of boost::filesystem::detail::copy() (operations.cpp:978) incorrectly goes through the nothrow version of boost::filesystem::copy_file (also copy_directories and copy_symlink). Hence when the exception is eventually thrown there is no handler and terminate is called.

by sudhanshu.gupta05@…, 4 years ago

Attachment: copy_exceptions.patch added

Patch contains the fix for the issue.

Note: See TracTickets for help on using tickets.