Menu

#643 _wstat64i32 fails on path ending with slash, causing failure in the filesystem library

v1.0 (example)
closed-fixed
niXman
None
5
2022-10-11
2017-08-02
Qrox
No

Hello,

The experimental filesystem library is failiing for my project, and from what I can gather, it's caused by _wstat64i32 not correctly handling paths ending with slash. Patch #34 fixed failure of stat & wstat when the path ends with a slash, however _wstat64i32 etc were not fixed. The current implementation of std::experimental::filesystem uses _wstat to retrieve path status, which is a macro which expands to _wstat64i32. This in turn causes the filesystem library to fail, e.g., create_directories can fail because the call is_directory will fail and return false for the parent directories (which ends with slash).

Discussion

  • niXman

    niXman - 2017-08-02

    Patch #34

    What are you talking about?

     
  • niXman

    niXman - 2017-08-02
    • assigned_to: niXman
     
  • Qrox

    Qrox - 2017-08-02
     
  • niXman

    niXman - 2017-08-03
    • status: open --> closed-fixed
     
  • Jonathan Wakely

    Jonathan Wakely - 2019-01-16

    The fix looks wrong, it means that _stat("regular_file/", &buf) will resolve to "regular_file" but a trailing slash should only be valid on a directory. Stripping the slash unconditionally is wrong.

    A better fix would be to append "." to the path, so that something ending in a slash is treated as a directory, but that won't work because of https://sourceforge.net/p/mingw-w64/bugs/782/

     
    • Jonathan Wakely

      Jonathan Wakely - 2019-01-17

      I take it back, on Windows "regular_file/" is the same path as "regular_file" so stripping the slash is fine, and works consistently with the expected behaviour on the OS.

      I was foolishly expecting Windows to have sane pathname handling, but I was wrong.

       
  • Jonathan Wakely

    Jonathan Wakely - 2020-11-27

    This seems to have been fixed for _stat and _wstat but not for _wstat64. Is that intentional?

     
  • Jonathan Wakely

    Jonathan Wakely - 2021-02-10

    ping?

     
    • Jonathan Yong

      Jonathan Yong - 2021-02-10

      I don't think it is intentional, is this still happening?

       
  • Jonathan Wakely

    Jonathan Wakely - 2021-02-10

    I see it with 7.0.0 which includes the fixes for this issue (but only _stat and _wstat), did _wstat64 change for 8.0.0?

     
  • Sundaram Ramaswamy

    @nixmann I can still reproduce the issue; stat() errors out on a directory path with trailing slash with -D_FILE_OFFSET_BITS=64.

    $ cat test.cpp
    #include <cassert>
    #include <sys/stat.h>
    
    int main() {
      struct stat s;
      assert(stat("C:/Windows/", &s) == 0);
    }
    
    $ g++ -std=c++11 -D_FILE_OFFSET_BITS=64 && a.exe
    Assertion failed: stat("C:/Windows/", &s) == 0, file test.cpp, line 6
    

    Should we reopen this or do I open a new bug?

    Toolchain Version: MinGW x86_64-12.2.0-release-posix-seh-rt_v10-rev0

     

    Last edit: Sundaram Ramaswamy 2022-10-11

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.