You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows: support info.size on wide-character systems (a.k.a. the C++17 upgrade) #3943
For any input image processed by the Sharp library using the toFile operation, when the output path contains non-ASCII characters, the info.size of the toFile operation will become undefined instead of being a numeric value.
What is the expected behaviour?
The info.size of the toFile function should be a numeric value.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
For "wide-character" paths the docs suggest using _wstat64 instead, however this doesn't support multi-byte strings, and therefore neither approach will work all of the time.
I think the best thing to do here is upgrade to using C++17 and take advantage of its new std::filesystem API. This would allow us to remove all the platform-specific STAT64_FUNCTION logic from sharp.
changed the title [-]When the output path of the `toFile` method contains non-ASCII characters, `info.size` will become undefined[/-][+]Windows: support info.size on wide-character systems (a.k.a. the C++17 upgrade)[/+]on Jan 13, 2024
Linux: Full C++17 support was added in gcc 9 (I tried a few linker flags to force it using gcc 8, but nothing seemed to work). This means ARM v6 and s390x prebuilt binaries will require upgrading from Debian buster (gcc 8.3.0) to bullseye (gcc 10.2.1), so the minimum glibc version will increase from 2.28 to 2.31.
macOS: Full C++17 support was added in 10.15, so the minimum version will increase from 10.13 to 10.15.
Windows: Tests that result in an attempt to call file_size on a directory are crashing with exit code 3221226505 rather than throwing an exception, which I guess might relate to some C++ runtime version mismatch (<experimental/filesystem> vs <filesystem>?).
In summary and on balance, the risks from upgrading currently outweigh the benefits it might bring.
Having revisited this, it looks like Windows was crashing when trying to (recursively? concurrently?) calculate the size of a directory, so I've updated the logic to prevent that happening - see bbe60cd
Activity
lovell commentedon Jan 13, 2024
Thanks for reporting, this appears to be due to the way that Windows exposes filesystem data to C code.
Here's the logic in sharp that reads the size of the output file:
sharp/src/pipeline.cc
Line 1295 in 0dcc7d5
For Windows, the
STAT64_FUNCTIONused is_stat64:sharp/src/pipeline.cc
Line 25 in 0dcc7d5
For "wide-character" paths the docs suggest using
_wstat64instead, however this doesn't support multi-byte strings, and therefore neither approach will work all of the time.https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions
I think the best thing to do here is upgrade to using C++17 and take advantage of its new
std::filesystemAPI. This would allow us to remove all the platform-specificSTAT64_FUNCTIONlogic from sharp.[-]When the output path of the `toFile` method contains non-ASCII characters, `info.size` will become undefined[/-][+]Windows: support info.size on wide-character systems (a.k.a. the C++17 upgrade)[/+]lovell commentedon Jan 20, 2024
I had a quick look at what might be required for this.
https://github.com/lovell/sharp/compare/upgrade-to-c++17
https://github.com/lovell/sharp/actions/runs/7594372372
Linux: Full C++17 support was added in gcc 9 (I tried a few linker flags to force it using gcc 8, but nothing seemed to work). This means ARM v6 and s390x prebuilt binaries will require upgrading from Debian buster (gcc 8.3.0) to bullseye (gcc 10.2.1), so the minimum glibc version will increase from 2.28 to 2.31.
macOS: Full C++17 support was added in 10.15, so the minimum version will increase from 10.13 to 10.15.
Windows: Tests that result in an attempt to call
file_sizeon a directory are crashing with exit code 3221226505 rather than throwing an exception, which I guess might relate to some C++ runtime version mismatch (<experimental/filesystem>vs<filesystem>?).In summary and on balance, the risks from upgrading currently outweigh the benefits it might bring.
lovell commentedon Nov 1, 2024
Having revisited this, it looks like Windows was crashing when trying to (recursively? concurrently?) calculate the size of a directory, so I've updated the logic to prevent that happening - see bbe60cd
Support info.size on wide-char systems via upgrade to C++17 #3943
lovell commentedon Apr 4, 2025
v0.34.0 now available and dependent upon C++17 - we are truly living in the future ;)
Support info.size on wide-char systems via upgrade to C++17 lovell#3943