Bug 65663 - libstdc++: writing mixed-size blocks through an std::ofstream to a SMB 2.1 share produces file corruption
Summary: libstdc++: writing mixed-size blocks through an std::ofstream to a SMB 2.1 sh...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.2.1
: P3 major
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-02 16:07 UTC by Kaarlo Kananen
Modified: 2015-12-16 00:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-04-02 00:00:00


Attachments
Preprocessed minimum-repro.ii (89.38 KB, text/plain)
2015-04-02 16:07 UTC, Kaarlo Kananen
Details
Original minimal reproduction .cpp (1.24 KB, text/plain)
2015-04-02 16:10 UTC, Kaarlo Kananen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kaarlo Kananen 2015-04-02 16:07:17 UTC
Created attachment 35216 [details]
Preprocessed minimum-repro.ii

Basic description of the problem:
Application writing into a libstdc++ ofstream from a Mac OS X 10.9 or 10.10 host to a samba shared folder hosted on Windows 7/8/2008 Server (the combination of OS X + Windows has to support SMB 2.1) can produce file corruption.

Reproductions steps:
You need two PCs visible to each other in a network: 
  a. a Mac running OS X 10.9 or later
  b. a Windows 7, Windows Server 2008 R2 or later PC.

1. Share a test folder on the Windows PC so that it is visible for the Mac in 
  the network

2. Connect the Mac to the windows shared folder using the smb protocol:
  e.g. in OSX Finder, connect to server smb://name-of-windows-pc/name-of-share
  (the share should now be visible under /Volumes/name-of-share/)
   
3. Compile this application on the Mac against libstdc++
  e.g. apple clang 5.0:
    clang++ ./minimum-repro.cpp -stdlib=libstdc++ -o minimum-repro
       g++ (4.0 or later):
    g++ ./minimum-repro.cpp -o minimum-repro

4. Run the compiled app on the Mac, with a single argument, a path to a file on the 
  network share:
  e.g. ./minimum-repro /Volumes/name-of-share/corruption-test.txt


The file will be written and it's contents read back and checked against the reference - they will not match in contents, i.e. the file has been corrupted on write.


The key to bug reproduction is to first write a small block of data (< 1022 bytes) and then a large block (> 0.5 MB) into an ofstream opened on the shared folder. The file will be corrupt from the 0.5 MB mark onwards.

Flushing the ofstream between the writes, writing smaller blocks all make the problem go away.


Built on OS X 10.8.5 and 10.9 with g++ 4.0.1, 4.2.1 and apple clang 5.0 and 5.1 using libstdc++ (6.0.9).

Tested on OS X 10.9, 10.10 (host) and Windows 7 and 8 (file server).

Version information:
$ g++-4.0 -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc_40/gcc_40-5494~315/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-arch=apple --with-tune=generic --host=i686-apple-darwin10 --target=i686-apple-darwin10
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5494)

$ g++-4.2 -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)

$ clang++ -v
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

$ clang++ -v
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix


Command-line to compile:
g++: g++ ./minimum-repro.cpp -o ./minimum-repro
clang: clang++ ./minimum-repro.cpp -stdlib=libstdc++ -o ./minimum-repro
Comment 1 Kaarlo Kananen 2015-04-02 16:10:08 UTC
Created attachment 35217 [details]
Original minimal reproduction .cpp

Full minimal reproduction source .cpp
Comment 2 Jonathan Wakely 2015-04-02 20:52:58 UTC
(In reply to Kaarlo Kananen from comment #0)
> Built on OS X 10.8.5 and 10.9 with g++ 4.0.1, 4.2.1 and apple clang 5.0 and
> 5.1 using libstdc++ (6.0.9).

Your version of libstdc++ is *ancient* (at least 7 years old) and not supported or maintained.

Please either report it to Apple, who provided you with the ancient library, or try with a newer version of libstdc++.
Comment 3 Martin Sebor 2015-12-16 00:54:00 UTC
Closing as INVALID since no feedback has been provided in over 8 months.