Public bug reported:

Please have a look at this test program:

#include <string>
#include <iostream>
#include <fstream>

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

int main()
{
    std::string s{'t', 'e', 0, 's', 't'};
    fs::path p(s);
    fs::create_directory(p);
    std::ofstream(p / "foo");
    fs::remove_all(p);
}


You can compile it with the following command:

  g++-8 -std=c++17 -o test test.cc -lstdc++fs

When you run it (without any arguments), it will try to create a
directory "te", create a file "foo" in it and then try to remove said
directory and all files in it.

When I run it on my local machine it crashes with the following error
message:

# ./test
terminate called after throwing an instance of 
'std::experimental::filesystem::v1::__cxx11::filesystem_error'
  what():  filesystem error: cannot remove all: Directory not empty [te
[1]    8180 abort      ./test

Through strace (log attached) I can tell that the crash is probably
triggered by running out file descriptors.

This bug also happens when compiling with gcc-7 or clang so I guess it's
really a bug in the std::filesystem library, not gcc itself.

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: libstdc++-8-dev 8-20180414-1ubuntu2
ProcVersionSignature: Ubuntu 4.15.0-34.37-generic 4.15.18
Uname: Linux 4.15.0-34-generic x86_64
ApportVersion: 2.20.9-0ubuntu7.3
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Fri Sep 14 13:56:03 2018
InstallationDate: Installed on 2018-03-05 (192 days ago)
InstallationMedia: Ubuntu 18.04 LTS "Bionic Beaver" - Alpha amd64 (20180305)
SourcePackage: gcc-8
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: gcc-8 (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug bionic wayland-session

** Attachment added: "test.log"
   https://bugs.launchpad.net/bugs/1792570/+attachment/5188765/+files/test.log

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1792570

Title:
  infinite loop in std::filesystem::remove_all when removing non-empty
  directory with NUL byte in name

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-8/+bug/1792570/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to