infinite loop in std::filesystem::remove_all when removing non-empty directory with NUL byte in name
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-8 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Please have a look at this test program:
#include <string>
#include <iostream>
#include <fstream>
#if __has_include(
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(
#include <experimental/
namespace fs = std::experiment
#endif
int main()
{
std::string s{'t', 'e', 0, 's', 't'};
fs::path p(s);
fs:
std::ofstream(p / "foo");
fs:
}
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::experimen
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
ProcVersionSign
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)