-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Simple Program.cs:
var p = "bigfile.bin";
if (File.Exists(p))
File.Delete(p);
// Larger than 4GiB to trigger 32-bit overflow
using (var s = new FileStream(p, FileMode.Create, FileAccess.Write, FileShare.None))
s.SetLength(1024 * 1024 * 1024 * 5L);
var fi = new FileInfo(p);
Console.WriteLine(fi.Length);
// Fails without large file support, works with it
var ret = Mono.Unix.Native.Syscall.lstat(p, out var stat);
if (ret != 0)
throw new Exception($"lstat failed: {ret}");
Console.WriteLine(stat.st_size);
And the test.csproj
file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mono.Unix" Version="7.1.0-final.1.21458.1" />
</ItemGroup>
</Project>
Running this program on 32-bit Linux gives:
> ./test
5368709120
Unhandled exception. System.Exception: lstat failed: -1
at Program.<Main>$(String[] args) in /test/Program.cs:line 15
Aborted
The cause is overflow in the file size because it has not been compiled with -DLARGE_FILE_SOURCE=1
.
I have a "kind-of" fix here:
424ee24
This should add the required directives to the compiler, but when I build with the latest Ubuntu, these options are enabled by default.
I am not sure what system the NuGet packages were built with, but I think an OS update would fix it.
I can make a PR with my changes, but they may not be needed.
Running with my own build gives this output:
5368709120
5368709120
Metadata
Metadata
Assignees
Labels
No labels