fix(libc): reject reverse copy lengths that are not a whole number of elements and oversized wmemcpy counts #16308
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16308"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-06T06:47:48Z.
What
fix(libc)(f269df38b3):__std_reverse_copy_trivially_copyable_{2,4,8}(throughReverseCopy<Size>) walked the source down by the element size without checking the range. A length that is not a multiple of the element size, or an inverted range, made the loop step past the begin pointer and read and write outside the source. The export now rejects such ranges withNotImplemented_nid_no_patch, like__std_min_4uand__std_max_4u.test(libc)(81b1022e16):core/libs/tests/GuestVectorAlgorithms.cppchecks that the 2, 4 and 8 byte exports throw for misaligned and inverted ranges and leave the destination untouched, and that whole-element and empty ranges still reverse.fix(libc)(c38d2e3aea):wmemcpyandwmemmovemultiplied the guest count bysizeof(char16_t)without a bound. For counts aboveSIZE_MAX / 2the product wrapped, so only a few bytes were copied and the destination was returned as if the whole count had been copied. Such counts now reject withNotImplemented_nid_no_patch.test(libc)(8ded3d3838):core/libs/tests/GuestWideStrings.cppchecks that both functions throw for a wrapping count and leave the destination unchanged.Tested
Linux, throwaway archive build of this head (
8ded3d3838):BUILD-EXIT 0, ctestguest_vector_algorithmsandguest_wide_strings(targetsguest_vector_algorithms_testsandguest_wide_string_tests) passed, 2 of 2.python3 tools/check_conventions.py --base upstream/mainandgit diff --checkare clean. The new cases were not run against the unfixed code; that they fail without the fixes is reasoned from the code. Not run on Windows or macOS.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)