public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows
@ 2020-06-18 18:27 reiter.christoph at gmail dot com
  2020-06-18 18:37 ` [Bug libstdc++/95749] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: reiter.christoph at gmail dot com @ 2020-06-18 18:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95749
           Summary: std::filesystem::file_size returns wrong size for
                    large files on Windows
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: reiter.christoph at gmail dot com
  Target Milestone: ---

Downstream report: https://github.com/msys2/MINGW-packages/issues/6585

----

#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdint.h>
#include <stdio.h>

int main(int argc, char** argv)
{

    uint64_t std_filesystem_file_size;
    uint64_t std_fstream_file_size;
    std::filesystem::path sourceFile = std::filesystem::current_path() /
"example_3GiB.bin";

    std::ofstream ofs(sourceFile);
    ofs << "this is some text in the new file\n";
    ofs.close();

    std::filesystem::resize_file(sourceFile,3221225472);
    std_filesystem_file_size = std::filesystem::file_size(sourceFile);

    std::ifstream in(sourceFile.string(), std::ifstream::ate |
std::ifstream::binary);
    std_fstream_file_size = in.tellg();

    std::cout << "3 GiB file:" << std::endl;
    std::cout << "std_filesystem_file_size: " << std_filesystem_file_size <<
std::endl;
    std::cout << "std_fstream_file_size: " << std_fstream_file_size <<
std::endl;
    return 0;
}

----

$ g++ -std=c++17 a.cpp
$ ./a.exe
3 GiB file:
std_filesystem_file_size: 18446744072635809792
std_fstream_file_size: 3221225472

----

The first value is wrong. My uneducated guess would be that
https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/libstdc%2B%2B-v3/src/filesystem/ops-common.h#L66
should use _wstat64() instead of _wstat and stat_type should be _stat64 instead
of _stat, otherwise things are limited to 32bit.

See
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019
for details.

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

* [Bug libstdc++/95749] std::filesystem::file_size returns wrong size for large files on Windows
  2020-06-18 18:27 [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows reiter.christoph at gmail dot com
@ 2020-06-18 18:37 ` redi at gcc dot gnu.org
  2020-08-10 11:04 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-18 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2020-06-18
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
     Ever confirmed|0                           |1
          Component|c++                         |libstdc++

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

* [Bug libstdc++/95749] std::filesystem::file_size returns wrong size for large files on Windows
  2020-06-18 18:27 [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows reiter.christoph at gmail dot com
  2020-06-18 18:37 ` [Bug libstdc++/95749] " redi at gcc dot gnu.org
@ 2020-08-10 11:04 ` cvs-commit at gcc dot gnu.org
  2020-08-10 11:06 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-10 11:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:b5cc5c95664347082100a504710f5ca0467306a5

commit r10-8600-gb5cc5c95664347082100a504710f5ca0467306a5
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Aug 10 12:04:27 2020 +0100

    libstdc++: Use _wstat64 for Windows [PR 95749]

    In order to handle large files on Windows we need to use stat API with
    64-bit st_size member.

    libstdc++-v3/ChangeLog:

            PR libstdc++/95749
            * src/filesystem/ops-common.h [_GLIBCXX_FILESYSTEM_IS_WINDOWS]
            (stat_type): Change to __stat64.
            (stat): Use _wstat64.

    (cherry picked from commit 9939be5758b52ed2fe1a7e56b94ce6d0f4d81580)

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

* [Bug libstdc++/95749] std::filesystem::file_size returns wrong size for large files on Windows
  2020-06-18 18:27 [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows reiter.christoph at gmail dot com
  2020-06-18 18:37 ` [Bug libstdc++/95749] " redi at gcc dot gnu.org
  2020-08-10 11:04 ` cvs-commit at gcc dot gnu.org
@ 2020-08-10 11:06 ` cvs-commit at gcc dot gnu.org
  2020-08-10 11:07 ` redi at gcc dot gnu.org
  2020-08-10 11:07 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-10 11:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:caac3ee7008286404323c4aa93ee0e1c4753c4c2

commit r9-8800-gcaac3ee7008286404323c4aa93ee0e1c4753c4c2
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Aug 10 11:10:26 2020 +0100

    libstdc++: Use _wstat64 for Windows [PR 95749]

    In order to handle large files on Windows we need to use stat API with
    64-bit st_size member.

    libstdc++-v3/ChangeLog:

            PR libstdc++/95749
            * src/filesystem/ops-common.h [_GLIBCXX_FILESYSTEM_IS_WINDOWS]
            (stat_type): Change to __stat64.
            (stat): Use _wstat64.

    (cherry picked from commit 9939be5758b52ed2fe1a7e56b94ce6d0f4d81580)

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

* [Bug libstdc++/95749] std::filesystem::file_size returns wrong size for large files on Windows
  2020-06-18 18:27 [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows reiter.christoph at gmail dot com
                   ` (2 preceding siblings ...)
  2020-08-10 11:06 ` cvs-commit at gcc dot gnu.org
@ 2020-08-10 11:07 ` redi at gcc dot gnu.org
  2020-08-10 11:07 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-10 11:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |9.4

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 9.4 and 10.3, thanks for the report.

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

* [Bug libstdc++/95749] std::filesystem::file_size returns wrong size for large files on Windows
  2020-06-18 18:27 [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows reiter.christoph at gmail dot com
                   ` (3 preceding siblings ...)
  2020-08-10 11:07 ` redi at gcc dot gnu.org
@ 2020-08-10 11:07 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-10 11:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also fixed on master by g:9939be5758b52ed2fe1a7e56b94ce6d0f4d81580 but I'm not
sure why that didn't get added here.

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

end of thread, other threads:[~2020-08-10 11:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 18:27 [Bug c++/95749] New: std::filesystem::file_size returns wrong size for large files on Windows reiter.christoph at gmail dot com
2020-06-18 18:37 ` [Bug libstdc++/95749] " redi at gcc dot gnu.org
2020-08-10 11:04 ` cvs-commit at gcc dot gnu.org
2020-08-10 11:06 ` cvs-commit at gcc dot gnu.org
2020-08-10 11:07 ` redi at gcc dot gnu.org
2020-08-10 11:07 ` redi 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).