public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "torsten.hilbrich at secunet dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/97731] New: terminate called in std::experimental::filesystem::recursive_directory_iterator
Date: Thu, 05 Nov 2020 13:51:46 +0000	[thread overview]
Message-ID: <bug-97731-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2020-11-05 13:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 13:51 torsten.hilbrich at secunet dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97731-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).