From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 86C7E3858C2B; Thu, 5 Nov 2020 13:51:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86C7E3858C2B From: "torsten.hilbrich at secunet dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: torsten.hilbrich at secunet dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Nov 2020 13:51:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97731 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=3D49506&action=3Dedit Reproducer for the problem The recursive_directory_iterator causes a call to terminate when an I/O err= or is happening on the directory to iterate. It originally occured in an environment where access to a directory was no longer possible and caused E= IO reported through a linux device-mapper target. In the test program this behaviour is simulated by replacing the readdir function with a mockup alwa= ys 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 =3D 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=3D0x55555559a050, skip_permission_denied=3Dtrue, ec=3D...) at dir-common.h:110 #1 0x000055555555eb39 in std::experimental::filesystem::v1::__cxx11::_Dir::advance ( this=3D0x55555559a050, skip_permission_denied=3Dtrue, ec=3D...) at dir.= cc:65 #2 0x000055555555ed39 in std::experimental::filesystem::v1::__cxx11::_Dir::advance ( this=3D0x55555559a050, skip_permission_denied=3Dtrue) at dir.cc:87 #3 0x000055555555d110 in std::experimental::filesystem::v1::__cxx11::recursive_directory_iterator::r= ecursive_directory_iterator (this=3D0x7fffffffdd90, p=3Dfilesystem::path "/tmp" =3D {...},=20 options=3Dstd::experimental::filesystem::v1::directory_options::none, ec=3D0x7fffffffdd60) at dir.cc:199 #4 0x000055555555c07c in std::experimental::filesystem::v1::__cxx11::recursive_directory_iterator::r= ecursive_directory_iterator (this=3D0x7fffffffdd90, __p=3Dfilesystem::path "/tmp" =3D {...}, __ec=3D...) 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=