Commit 2afab64
committed
fix: tinyxml2 mangles non-ASCII Windows paths via ANSI-codepage fopen()
Real windows-2022 CI still crashed mc3_roundtrip after tonight's earlier
fix, for a different reason: Mc3::writeFileAtomically() threw
AtomicFinalizeError ("Input/output error") finalizing the
STAB-0555 Czech+Japanese filename roundtrip case.
Root-caused with a real repro, not guesswork: found Wine actually runs
trivial MinGW-cross-compiled console programs fine in this sandbox
(only the full GUI editor hits the previously-documented SIGSYS block),
and reused an existing unused cmake-build-verification-windows-standalone/
+ Wine-prefix setup from an earlier session to build and run the actual
mc3_roundtrip_test.exe under Wine. A minimal writeFileAtomically()-only
repro passed, ruling out the atomic-write primitive itself. The real
test reproduced the crash with a clearer message ("No such file or
directory") pointing at Mc3XmlWriter.cpp/Mc3XmlParser.cpp: both called
tinyxml2's SaveFile(const char*)/LoadFile(const char*) with
path.string() -- a UTF-8-encoded narrow string. tinyxml2 opens that
with plain fopen(), which on Windows converts narrow strings via the
process's ANSI code page, not UTF-8, so a non-ASCII path makes fopen()
open/create a different, mangled file than the one rename() expects
afterward. Mc3JsonWriter/Mc3JsonParser never had this bug -- they
already use std::ifstream/std::ofstream directly with the path object,
which libstdc++ opens via the native wide string on Windows.
Fixed by adding saveXmlFileUnicodeSafe()/loadXmlFileUnicodeSafe()
helpers (#ifdef _WIN32) that open the file via
_wfopen(path.c_str(), ...) -- the path's native wide representation,
no narrow conversion -- and hand tinyxml2 the FILE* overload instead;
POSIX keeps the original narrow call unchanged. Also widened
writeFileAtomically()'s finalize retry budget from 5x20ms to 20x50ms as
defense-in-depth against the slower antivirus-scan lock the original
CI symptom is also consistent with.
Verified: mc3_roundtrip/mc3_atomic_write/mc3_load_policy/
mc3_json_load_policy (including the utf8/spaces/non-ascii-name cases)
and the full 28-test standalone mc3 suite all pass under a real
MinGW+Wine repro of this exact scenario -- the strongest verification
any Windows-only fix has had this session. Also re-verified clean under
Linux Clang ASan+UBSan (29/29 mc3_* tests, zero regressions).1 parent 26ff25c commit 2afab64
4 files changed
Lines changed: 105 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
274 | 308 | | |
275 | 309 | | |
276 | 310 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
28 | 38 | | |
29 | 39 | | |
30 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
30 | 54 | | |
31 | 55 | | |
32 | 56 | | |
| |||
1733 | 1757 | | |
1734 | 1758 | | |
1735 | 1759 | | |
1736 | | - | |
| 1760 | + | |
1737 | 1761 | | |
1738 | 1762 | | |
1739 | 1763 | | |
| |||
2058 | 2082 | | |
2059 | 2083 | | |
2060 | 2084 | | |
2061 | | - | |
| 2085 | + | |
2062 | 2086 | | |
2063 | 2087 | | |
2064 | 2088 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
21 | 45 | | |
22 | 46 | | |
23 | 47 | | |
| |||
936 | 960 | | |
937 | 961 | | |
938 | 962 | | |
939 | | - | |
| 963 | + | |
940 | 964 | | |
941 | 965 | | |
942 | 966 | | |
0 commit comments