public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/97731] New: terminate called in std::experimental::filesystem::recursive_directory_iterator
@ 2020-11-05 13:51 torsten.hilbrich at secunet dot com
  2020-11-05 14:10 ` [Bug libstdc++/97731] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: torsten.hilbrich at secunet dot com @ 2020-11-05 13:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97731

            Bug ID: 97731
           Summary: terminate called in
                    std::experimental::filesystem::recursive_directory_ite
                    rator
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: torsten.hilbrich at secunet dot com
  Target Milestone: ---

Created attachment 49506
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49506&action=edit
Reproducer for the problem

The recursive_directory_iterator causes a call to terminate when an I/O error
is happening on the directory to iterate. It originally occured in an
environment where access to a directory was no longer possible and caused EIO
reported through a linux device-mapper target. In the test program this
behaviour is simulated by replacing the readdir function with a mockup always
failing with errno set to EIO.

We initially found this problem with libstdc++ as provided with gcc 8.3.0. But
I also checked the version from gcc 10.2 and could reproduce the problem.

The testing code test.cpp is attached to this ticket.

Here is an example session:

$ g++ -o test test.cpp -lstdc++fs
$ ./test
terminate called after throwing an instance of
'std::experimental::filesystem::v1::__cxx11::filesystem_error'
  what():  filesystem error: directory iterator cannot advance: Input/output
error
Aborted (core dumped)

I already looked at the code and thing I found the culprit.

In recursive_directory_iterator(const path&, directory_options options,
error_code*) (dir.cc:199) the following method call is found:

   if (sp->top().advance(ec))

This calls the method "bool advance(bool skip_permission_denied = false)"
within _Dir, implicitly converting the std::error_code* to bool.

This way, we get roughly the following stack trace:

#0  std::filesystem::_Dir_base::advance (this=0x55555559a050,
skip_permission_denied=true, ec=...)
    at dir-common.h:110
#1  0x000055555555eb39 in
std::experimental::filesystem::v1::__cxx11::_Dir::advance (
    this=0x55555559a050, skip_permission_denied=true, ec=...) at dir.cc:65
#2  0x000055555555ed39 in
std::experimental::filesystem::v1::__cxx11::_Dir::advance (
    this=0x55555559a050, skip_permission_denied=true) at dir.cc:87
#3  0x000055555555d110 in
std::experimental::filesystem::v1::__cxx11::recursive_directory_iterator::recursive_directory_iterator
(this=0x7fffffffdd90, p=filesystem::path "/tmp" = {...}, 
    options=std::experimental::filesystem::v1::directory_options::none,
ec=0x7fffffffdd60) at dir.cc:199
#4  0x000055555555c07c in
std::experimental::filesystem::v1::__cxx11::recursive_directory_iterator::recursive_directory_iterator
(this=0x7fffffffdd90, __p=filesystem::path "/tmp" = {...}, __ec=...)
    at /usr/include/c++/9/experimental/bits/fs_dir.h:280
#5  0x000055555555bb5d in main () at ./test.cpp:17

and finally, an exception is thrown via a method declared noexcept, causing the
termination of the program.

Torsten

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-10-04 11:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 13:51 [Bug libstdc++/97731] New: terminate called in std::experimental::filesystem::recursive_directory_iterator torsten.hilbrich at secunet dot com
2020-11-05 14:10 ` [Bug libstdc++/97731] " redi at gcc dot gnu.org
2020-11-05 14:14 ` redi at gcc dot gnu.org
2020-11-05 18:01 ` cvs-commit at gcc dot gnu.org
2020-11-05 18:05 ` redi at gcc dot gnu.org
2020-11-09 14:53 ` cvs-commit at gcc dot gnu.org
2020-11-09 15:27 ` cvs-commit at gcc dot gnu.org
2020-11-09 15:29 ` redi at gcc dot gnu.org
2022-02-01 21:58 ` cvs-commit at gcc dot gnu.org
2023-10-04 11:29 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).