Commit ac95b67
committed
libretro-common/vfs_smb: fix silent truncations in read/write/stat
Three low-priority but real correctness issues in
vfs_implementation_smb.c. None are memory-safety bugs; all three
are silent data or size corruption that would confuse callers on
unusual inputs.
vfs_smb: cap len in retro_vfs_file_read_smb
smb2_read takes uint32_t count, but the wrapper passes a
uint64_t len straight through. For len > UINT32_MAX the high
bits are silently dropped and smb2_read issues a truncated
read. The caller receives a short return count and, depending
on the loop, may re-issue from the wrong file offset or treat
the short read as EOF.
Fix: cap len at UINT32_MAX before the call. The VFS read
contract already allows short reads (all well-behaved callers
loop), so the caller simply re-issues for the remaining bytes.
vfs_smb: cap len in retro_vfs_file_write_smb
Identical bug class on the write side: smb2_write takes
uint32_t count. Same fix.
vfs_smb: saturate retro_vfs_stat_smb size
*size is int64_t but st.smb2_size is uint64_t. A naked cast
for files > INT64_MAX (8 EiB) produces a negative value that
callers may interpret as an error. Saturate to INT64_MAX.
Practically unreachable -- no filesystem today holds 8 EiB
files -- but the fix is two lines and keeps sign semantics
consistent with the matching fix in retro_vfs_stat_impl
(commit cf73f1a).
VC6 compatibility: the file is only compiled when libsmb2 is
linked, which in practice is a modern toolchain concern. For
correctness anyway, the fix uses UINT32_MAX and INT64_MAX which
are defined by the existing VC6 stdint shim at
include/compat/msvc/stdint.h, and adds an explicit
reliably available even if libsmb2's transitive include chain
ever changes.
Regression test: NONE. Exercising the SMB VFS layer requires a
live SMB server and an authenticated mount, which is
impractical for a self-contained sample that runs in CI. The
existing nbio_test and config_file_test exercise the non-SMB VFS
paths; a regression that broke those paths would still surface.
The fixes themselves are small (two cap statements and a
ternary) and reviewed directly.1 parent 18e15ad commit ac95b67
1 file changed
Lines changed: 25 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
352 | 353 | | |
353 | 354 | | |
354 | 355 | | |
355 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
356 | 365 | | |
357 | 366 | | |
358 | 367 | | |
| |||
370 | 379 | | |
371 | 380 | | |
372 | 381 | | |
373 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
374 | 389 | | |
375 | 390 | | |
376 | 391 | | |
| |||
571 | 586 | | |
572 | 587 | | |
573 | 588 | | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
574 | 594 | | |
575 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
576 | 598 | | |
577 | 599 | | |
578 | 600 | | |
| |||
0 commit comments