Skip to content

fix(libc): reject oversized secure copy destinations - #4455

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
SibteProf:fix/libc-secure-copy-size-limits
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
SibteProf:fix/libc-secure-copy-size-limits

Conversation

@SibteProf

Copy link
Copy Markdown
Contributor

What

memcpy_s and memmove_s currently accept destination sizes above RSIZE_MAX. A call with a small count can incorrectly succeed; if the source is null or the count exceeds the destination size, the error path passes the oversized length to memset, potentially writing beyond the destination before returning an error.

Reject oversized destination sizes before copying or clearing. Use SIZE_MAX >> 1, matching the existing memset_s limit, and return the existing guest ERANGE value (34). Valid destination sizes retain their existing behavior: a constraint violation clears only the declared destination, and memmove_s still supports overlap.

The no-write rule follows C11 N1570, K.3.7.1.1 paragraphs 2–3 and K.3.7.1.2 paragraphs 2–3. Annex K requires a nonzero error, without prescribing its numeric value. The console's exact limit/error and the existing omission of constraint-handler invocation are recorded in TechnicalDebt.

This addresses the separate memcpy_s/memmove_s gap Fishybeing noted in #3166; that issue's memset_s fix already merged as #3280. This implementation and its regression tests are new.

Adds behavioral regression coverage for both functions: destination sizes RSIZE_MAX + 1 and SIZE_MAX, zero/small/oversized counts, null and non-null sources, the accepted RSIZE_MAX boundary, and guard bytes around a valid destination cleared on error. The new test fails against unchanged main and passes with the fix.

This fixes functions already counted as implemented; it does not increase the system-library progress percentage. No title-specific unblock is claimed.

Tested

Windows 11 Pro, WinLibs MinGW-w64 GCC 15.2.0 (15.2.0posix-14.0.0-ucrt-r7), Release, BUILD_TESTING=ON.

  • Full build: cmake --build build --parallel 6 passed.
  • Patched PRXs: cmake --build build --target libs --parallel 6 passed.
  • CTest selection passed 8/8: guest_strings, guest_wide_strings, guest_math, guest_memory, guest_memory_pool_stats, patched_libraries, conventions_function_bodies, and test_registration. The new guest_strings case runs in about 0.01–0.04 seconds on this host.
  • Negative control: rebuilt guest_string_tests with unchanged origin/main's Strings.cpp, keeping the new tests; guest_strings failed. Restoring the fix and rebuilding made it pass.
  • python tools/check_conventions.py --base origin/main and git diff origin/main --check passed.
  • python tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch fix/libc-secure-copy-size-limits reported no overlap with open PRs.

Base: ffa198407e70296c50d0011a4157a430408dd00e. The complete CTest suite was not run. Linux and console/title testing have not been performed; maintainer-triggered full Linux/Windows CI is still required.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes (OpenAI Codex)

@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@oneandonlydean
oneandonlydean merged commit b9f194a into boykopovar:main Oct 12, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants