Repository navigation
fix(libc): preserve partial wcsftime output on overflow - #10895
Conversation
Write wide literals and conversion results directly while sharing the current time-format rules. Cover truncated output and retain documented argument-handling gaps.
MarcZX10
left a comment
There was a problem hiding this comment.
The direct wide-character formatter preserves literal UTF-16 units, the established conversion behavior, and the tested partial-write boundary semantics. I reviewed the changed path and test cases; the author reports a focused ASan/UBSan harness, and the repository policy checks pass. Product build jobs are skipped by repository policy, so this approval does not claim an independent full integration build.
|
@StoneDC Please trim the wcsftime debt entry to the remaining gaps. CONTRIBUTING.md asks that a fixed gap be cut from the entry, rather than replaced with a description of the corrected behavior. Drop the direct-write/prefix introduction and keep the strftime gaps, null argument and oversized-count differences; the production change and tests can stay as they are. |
Remove the corrected direct-write and partial-output description, keeping the outstanding formatting, null-argument and oversized-count gaps.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
@oneandonlydean Addressed in 920903d. The wcsftime debt entry now contains only the remaining strftime gaps, null-argument behavior and oversized-count restriction. The direct-write/prefix introduction has been removed; production code and tests are byte-identical to 0ce70b4. Conventions and whitespace checks pass. No runtime tests were rerun for this documentation-only follow-up; the previously reported integration-build limitations still apply. I also investigated the progress bot's "went back to stubs" classification without changing the formatter or the reporting tool.
The three ISO-week guards already exist on the base branch and are documented in the strftime debt entry. Previously wcsftime called the exported strftime path, across which the helper analysis did not propagate that classification. I reproduced the baseline's empty stub-match list and the candidate's |
thepoppfish
left a comment
There was a problem hiding this comment.
Independent native Windows validation of exact head 920903db939cef0943f4f381f1cc0a9df3e3f055. No blocking finding in the formatter change. Confirmed that its production/test blobs are unchanged from 0ce70b465; the latest commit only trims the debt entry.
Windows 11 build 26200, MSYS2 UCRT64 GCC 16.2.0-6 (SEH), CMake 4.3.1, Ninja 1.13.2:
- An out-of-tree harness compiles the actual
Time.cpp,Environment.cpp,Multibyte.cpp,FormattingWide.cpp, and complete repositoryGuestWideFormatting.cpp/GuestStrftime.cpp. Both CTest cases pass, including three consecutive repeats of each. This exercises the UTF-16 literals/surrogates, capacity/guard checks, modifiers/composites, errno and oversized-count boundaries in the submitted tests, alongside the existing narrow formatter checks. - Negative control: replace only
wcsftimewith main's prior implementation, restoring its required<memory>/<new>includes. The wide test fails atwcsftime written prefix(0.06 s), whileguest_strftimestill passes. - Support supplies guest errno as
Process.cppdoes, a throwing unimplemented entry, and Windows abort-UI suppression. Two additional stream symbols are link-only placeholders:fgetwcaborts if called, and__stdoutpis null. The submitted tests do not exercise stream I/O. A GDB hardware read watchpoint on__stdoutp, set atmain, lets each complete test exit normally without a read; the aborting input placeholder is not called. Neither placeholder implements or changes time/conversion/memory-formatting logic. Full replay files are below. - Conventions and whitespace checks pass. Merge-tree against main
2742004ed28f765c7147db0e0269ff5868e9eb6fis clean.
This adds focused native Windows evidence to the author's Linux results. It is not a full shared-libc/runtime integration build, stream-I/O test, sanitizer run, console measurement, game run or cross-PR composition test. No maintainer-triggered upstream native CI is claimed. AI-assisted testing and review: yes (OpenAI Codex).
Out-of-tree replay files
CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(AnyPS5WideTimeReview LANGUAGES CXX)
enable_testing()
set(REPO "${CMAKE_CURRENT_LIST_DIR}/../review-10895" CACHE PATH "Exact PR checkout")
set(TIME_SOURCE "${REPO}/core/libs/prx/libc/src/Time.cpp" CACHE FILEPATH "Time source under test")
add_library(time_sources OBJECT
"${TIME_SOURCE}"
"${REPO}/core/libs/prx/libc/src/Environment.cpp"
"${REPO}/core/libs/prx/libc/src/Multibyte.cpp"
"${REPO}/core/libs/prx/libc/src/FormattingWide.cpp"
IoPoison.cpp
Support.cpp)
target_compile_features(time_sources PUBLIC cxx_std_20)
target_include_directories(time_sources PUBLIC "${REPO}/core/libs")
target_compile_options(time_sources PUBLIC -O1 -g -Wall -Wextra -ffunction-sections -fdata-sections)
foreach(pair IN ITEMS "guest_wide_formatting|GuestWideFormatting" "guest_strftime|GuestStrftime")
string(REPLACE "|" ";" parts "${pair}")
list(GET parts 0 name)
list(GET parts 1 source)
add_executable(${name} "${REPO}/core/libs/tests/${source}.cpp")
target_link_libraries(${name} PRIVATE time_sources)
target_link_options(${name} PRIVATE -Wl,--gc-sections)
add_test(NAME ${name} COMMAND ${name})
set_tests_properties(${name} PROPERTIES TIMEOUT 30)
endforeach()Support.cpp:
#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/General.hpp"
#include <cerrno>
#include <cstdlib>
#include <stdexcept>
[[maybe_unused]] const unsigned int abortFlags = _set_abort_behavior(0, _CALL_REPORTFAULT);
extern "C" int* APS5_VABI __error_nid_postfix() {
return &errno;
}
extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) {
throw std::runtime_error(name);
}IoPoison.cpp:
#include "prx/libc/include/Api.hpp"
#include <cstdio>
#include <cstdlib>
extern "C" {
FileStream* __stdoutp_nid_postfix = nullptr;
std::int32_t APS5_VABI fgetwc_nid_postfix(FileStream*) {
std::fputs("Unexpected stream I/O in memory-formatting harness\n", stderr);
std::abort();
}
}Use GCC 16.2 UCRT64 bin first on PATH, followed by CMake/Ninja. Configure with cmake -S native-wide-time-review -B native-wide-time-review/build16 -G Ninja -DREPO=<exact-PR-checkout> -DCMAKE_CXX_COMPILER=<GCC16-bin>/g++.exe -DCMAKE_BUILD_TYPE=Release, build, then run ctest --test-dir native-wide-time-review/build16 --output-on-failure. The negative control uses a separate build directory and -DTIME_SOURCE=<copy-with-only-old-wcsftime-and-required-includes>. For each executable, gdb --batch --nx -ex "set auto-load python-scripts off" -ex start -ex "rwatch __stdoutp_nid_postfix" -ex continue --args <exe> exits normally without a watchpoint hit after setup.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head 920903db939cef0943f4f381f1cc0a9df3e3f055.
The wide formatter now writes each formatted piece directly into the caller buffer, retaining the prefix when capacity is exhausted and writing a terminator only for a complete result. The new tests cover capacities around each result length, zero capacity, empty output, multibyte UTF-16 units, surrogate code units, composite/modified/unknown conversions, errno, and the oversized-count boundary. The diff also exercises narrow strftime through the shared formatter; the author’s target-level harness ran both wide and narrow formatting tests under ASan/UBSan, with repeated runs and a negative control using the baseline wcsftime implementation.
The author updated the debt entry to retain only the remaining differences requested in review. I found no new overlap implementing partial wide output; #8855 is the merged predecessor. Hosted macOS and Ubuntu Debug/Release register-context, relinker, ASan, conventions, labels, and report checks pass; Windows product jobs are skipped by path policy. Local diff/convention checks pass. The PR explicitly discloses that the target-level harness is not a full product/shared-libc build and that native Windows/macOS, title, and console validation were not run; I did not independently run the harness.
No blocking issue found in the scoped partial-output change.
AI-assisted: yes.
|
The overlap check for my #10987 flags I propose #10895 goes first, then I rebase #10987 onto the merged result, resolve any overlap, and declare |
|
The overlap check now flags #10987 on |
|
I manually compared the exact current heads of #10895 and my #10987. The three-way merge reports a conflict in |
|
@MarcZX10 Thanks for checking the current heads so carefully! I'm happy to keep the agreed order: #10895 first, then #10987 rebased onto the merged result. I also see you've already recorded When resolving the test conflict, please retain both the partial-output/capacity cases and the UTF-8-to-UTF-16 comparison changes, then rerun the wide-formatting and time-conversion tests. Thanks again for coordinating this! |
|
@StoneDC sorry: #11004 was merged before this PR, so the order we agreed did not hold, and the conflicts are now on your side. I merged current
With that, AI-assisted: yes |
|
@StoneDC Sorry, #11004 went in ahead of this PR even though we'd agreed this one first. @verusferro's resolution above looks right: |
|
@oneandonlydean @verusferro Resolved and pushed
The PR description now records these exact-head results and the remaining limits. Local full product configuration is still blocked by missing dependencies; native Windows focused validation did not complete because the available toolchain's ABI/exception support failed to compile/link. No full shared-libc, AI-assisted: yes. |
|
A Windows run of
|
|
Data on overflow behaviour from the Setup: a scratch loader runs the decrypted
All 21 sizes from 0 to 20 for these three formats fit one rule for the titles'
So a too-small buffer can return a nonzero count for a string with conversions missing, and characters from an abandoned piece can follow the terminator ( Random formats: 200,000 formats of 1 to 3 conversions with This is the titles' bundled AI-assisted: yes (Claude Code). |
|
@JJenkx Thanks for the measurements and for distinguishing the titles' bundled @oneandonlydean @MarcZX10 Could you confirm which reference this PR's I checked the code at the unchanged PR head That differs from the bundled modules in your report, which rewind the logical write position after an overflowing piece while retaining the written bytes, continue formatting, and can terminate and return a nonzero count with conversions omitted. For example, using your
The narrow These module results are your measurements; I have not independently rerun the loader or measured firmware libc. The existing passing regression tests check the PR's current prefix-preservation expectations, so they do not resolve this compatibility question. If firmware libc is the intended reference, do we have measurements for these same small-buffer cases to compare? Once the target is confirmed, I can adjust the wide implementation and regression expectations to the supported behavior. No code has been changed for this clarification. AI-assisted: yes. |
|
@StoneDC a native comparison of this head ( Method: a scratch loader calls the titles'
Every remaining difference is a call that fails (both sides return 0), and in all 15,913 the only differing element is the first one. When the output doesn't fit, the titles write as much as fits, as this PR now does, and then store The narrow Not covered:
The probe is a native harness (a title's decrypted AI-assisted: yes (Claude Code). |
Reference targetGiven the scope recorded in #8855, I would treat firmware For the newly reported multi-piece overflow and error boundaries, I agree we need a firmware measurement before changing the implementation or claiming a match. Until then, keeping the current tested behavior and documenting the remaining difference is the evidence-backed choice. This clarifies the intended reference, but it does not independently resolve the unmeasured cases or replace maintainer confirmation. |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — approved
I clarified the reference question in my follow-up: for the console behavior scoped by #8855, firmware libSceLibcInternal.sprx is authoritative; title-bundled libc.prx results are cross-checks and cannot establish firmware behavior when they differ. The current description now explicitly keeps the multi-piece/error boundary behavior unclaimed and unchanged pending a firmware measurement, and retains the remaining gaps in debt.
The exact head 5be64730a23cb09a9ce5ed0136f4ec074a13f3a7 preserves the previously reviewed formatter and tests while merging current main; the author reports the repository test suites plus ASan/UBSan harness passing, with a negative control. The documented full product/integration limitations are clear. Hosted relinker and policy checks pass; Linux and Windows product jobs are skipped by workflow policy. I did not rerun the harness locally.
|
@MarcZX10 @PrivacyOnion a firmware 13.42 measurement of the open cases. Setup. I ran the decrypted firmware 13.42
That is 895 cases, two byte-identical runs. What the module does. This model reproduces every case, return value and every output unit:
So when a conversion doesn't fit:
A literal that doesn't fit always returns 0 with everything before it in place. No case changed errno. Capacity 0 writes nothing and returns 0. The empty format at capacity 1 or more writes only the terminator and returns 0. Against this head (
The other 527 match, including the literal-only overflow, the empty format and errno. For comparison, Not covered: AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — changes requested
The new firmware 13.42 measurement materially changes the evidence behind my earlier approval. The reported native comparison covers 895 cases twice and finds 368 differences on this head: 199 cases where the firmware returns the written prefix but this code returns 0, and 169 where it continues writing later format pieces after a conversion does not fit. The earlier review explicitly left those multi-piece/error boundaries unclaimed pending firmware evidence; that evidence is now available and contradicts the current behavior.
Please add focused regressions for the measured cases and align the implementation and debt description with the firmware results, or narrow the PR so it no longer claims the unverified multi-piece behavior. I am changing the review to request changes because the current tests do not cover the newly measured cases. The report is a firmware-module run on a PC, not a physical-console result, so please retain that limitation in the description.
|
Follow-up on the review fixes at head Implemented the reported firmware-style wide-formatting overflow behavior: a conversion advances the logical position only when its whole result fits, while later pieces can overwrite an abandoned partial conversion. Literal overflow still stops. Added 22 boundary vectors and retained the complete-output tests; the timezone fixture now sets and restores guest TZ explicitly. Validation at this exact head: the real shared-libc wide-formatting/time CTests pass 4/4 on both Windows and Linux; the supplementary actual-source ASan+UBSan harness also passes 4/4. Restoring only the old formatter makes the current regression fail at the firmware-piece assertion. The reference evidence is the reported firmware 13.42 module run on a PC; I have not independently rerun its private loader/895-case campaign or tested PS5 hardware. Remaining unverified cases are listed in the PR/debt entry. Build run 40867077680 completed successfully for every executed job, including full Windows and the relinker/ASan jobs. Full Linux was skipped. Hosted-check snapshot checked on 2026-10-30 UTC+08:00 (2026-10-29 UTC) for this head: 16 passed, 1 skipped; no failures. Current checks. Pending and skipped checks are not counted as passes. The PR description contains the detailed validation scope and limitations. Please re-review the updated head when convenient. AI-assisted: yes. |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — new head, looks good
The firmware-piece overflow finding is now covered by boundary cases, and all four focused formatting/time tests pass locally.
What I ran
- Reviewed head 3d9db7d against current main bb04a4f.
- Current-main merge preview completed cleanly (tree 8dbddde8864d20874b5042b1a6cfd434b61b86c0).
- Debian Linux 6.1.190, x86_64, GCC 12.2.0, CMake/Ninja.
- Built the actual shared-libc targets and ran four focused CTests.
- Replaced only Time.cpp with current-main source while retaining the PR regression test, then restored the PR source and reran the suite.
- Ran conventions and whitespace checks. Hosted checks are reported separately below.
cmake --build /dev/shm/AnyPS5-build-12915-full --target guest_wide_formatting_tests guest_strftime_tests guest_time_conversion_tests guest_time_extras_tests -j 2
ctest --test-dir /dev/shm/AnyPS5-build-12915-full -R '^guest_(wide_formatting|strftime|time_conversion|time_extras)$' --output-on-failure
git show upstream/main:core/libs/prx/libc/src/Time.cpp > core/libs/prx/libc/src/Time.cpp
cmake --build /dev/shm/AnyPS5-build-12915-full --target guest_wide_formatting_tests -j 2
ctest --test-dir /dev/shm/AnyPS5-build-12915-full -R '^guest_wide_formatting$' --output-on-failure
git checkout -- core/libs/prx/libc/src/Time.cpp
python3 tools/check_conventions.py --base upstream/main
git diff --check upstream/main...HEADResults
| Check | Result |
|---|---|
| Current-main merge preview | Clean; tree 8dbddde8864d20874b5042b1a6cfd434b61b86c0 |
| Shared-libc/test build | Passed |
| Four focused formatting/time CTests | 4/4 passed |
| Baseline formatter negative control | Failed at the expected firmware-piece assertion |
| Restored PR formatter | 4/4 passed |
| Conventions and diff check | Passed |
| Hosted checks | Executed jobs pass; full Linux job skipped |
Unedited local test output
Internal ctest changing into directory: /dev/shm/AnyPS5-build-12915-full
Test project /dev/shm/AnyPS5-build-12915-full
Start 514: guest_time_conversion
1/4 Test #514: guest_time_conversion ............ Passed 0.34 sec
Start 517: guest_time_extras
2/4 Test #517: guest_time_extras ................ Passed 0.08 sec
Start 522: guest_wide_formatting
3/4 Test #522: guest_wide_formatting ............ Passed 0.02 sec
Start 596: guest_strftime
4/4 Test #596: guest_strftime ................... Passed 0.03 sec
100% tests passed, 0 tests failed out of 4
Total Test time (real) = 0.74 sec
Unedited negative-control output
Internal ctest changing into directory: /dev/shm/AnyPS5-build-12915-full
Test project /dev/shm/AnyPS5-build-12915-full
Start 522: guest_wide_formatting
1/1 Test #522: guest_wide_formatting ............Subprocess aborted***Exception: 0.06 sec
snwprintf_s: wcsftime firmware piece units
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.35 sec
The following tests FAILED:
522 - guest_wide_formatting (Subprocess aborted)
baseline_formatter_control_exit=8
Unedited restored-test and conventions output
Internal ctest changing into directory: /dev/shm/AnyPS5-build-12915-full
Test project /dev/shm/AnyPS5-build-12915-full
Start 514: guest_time_conversion
1/4 Test #514: guest_time_conversion ............ Passed 0.33 sec
Start 517: guest_time_extras
2/4 Test #517: guest_time_extras ................ Passed 0.09 sec
Start 522: guest_wide_formatting
3/4 Test #522: guest_wide_formatting ............ Passed 0.02 sec
Start 596: guest_strftime
4/4 Test #596: guest_strftime ................... Passed 0.01 sec
100% tests passed, 0 tests failed out of 4
Total Test time (real) = 0.98 sec
restored_pr_test_exit=0
All conventions checks passed.
diff_check_exit=0
Negative control
| Assertion | Mutation | Result |
|---|---|---|
| Conversion overflow continuation | Replaced only Time.cpp with current-main source while retaining the PR tests | guest_wide_formatting failed at the expected firmware-piece assertion (exit 8) |
| Restored PR source | Restored the reviewed Time.cpp | All four CTests passed |
Findings
Blocking
None found in the reviewed head.
Non-blocking
The follow-up comment 6502794473, created on October 29, says its hosted-check snapshot was checked on October 30. The current hosted checks are available and executed jobs pass; please correct or remove that future-dated snapshot line so the report timeline remains accurate.
Sources
- Wide formatter implementation at the reviewed head
- Firmware-piece and boundary regression tests at the reviewed head
- Libc debt entry at the reviewed head
- Reported firmware 13.42 native-PC measurements
Not verified
- I did not reproduce the firmware module run/private 895-case campaign or run on PS5 hardware.
- The CTests ran on the exact PR head; I computed a clean current-main merge preview but did not run CTests on a synthetic merged working tree.
- Game-level behavior, %Z/%z differences, and unmeasured conversion-failure cases remain unverified.
|
Thanks for the re-check and approval. I clarified the original follow-up comment: its snapshot used the local date 2026-10-30 in UTC+08:00, corresponding to 2026-10-29 UTC. The line now explicitly states both dates, so its timeline agrees with GitHub's UTC creation date. The reviewed head remains AI-assisted: yes. |
|
@StoneDC to close the question you asked us: yes, firmware |
|
@oneandonlydean Thanks for closing the target question and checking The reviewed wide-formatting behavior and separate narrow strftime stop-on-overflow behavior remain unchanged. Source head is still Current-head checks. AI-assisted: yes. |
What
Align wide time-formatting overflow with the reported native-PC run of firmware 13.42
libSceLibcInternal.sprx, following the requested review changes.A conversion writes as many 16-bit units as fit, but advances the logical position only when the complete conversion fits. Otherwise later format pieces reuse that position, and final termination may return a shorter nonzero prefix while retaining partial units beyond the terminator. A literal that does not fit still stops and returns zero. Expand compound conversions as complete pieces; retain the separate narrow
strftimestop-on-overflow behavior.Add 22 explicit boundary vectors derived from the reported rule and examples, including
%Y-%m-%dat each boundary, partial compound conversions, later literals, modifiers, unknown conversions, surrogate units, zero capacity, empty format, errno and untouched guards. Retain complete-output/reference cases and capacity safety checks, replacing the superseded flat-prefix overflow expectation. Set and restore the guest TZ explicitly so the existing%Zcomparison does not depend on the host's localized default zone name.Update the existing libc debt entry. The reference report is a firmware-module execution on a PC, not a physical-console measurement. I have not independently run its private loader, reproduced its 895-case reference campaign or verified
%Z/%z, conversion failures, null-argument differences or the large-count restriction. The last two remain unchanged gaps. The agreed test-integration order remains #10895 before #10987.Maintainer confirmation on 2026-11-01: firmware libSceLibcInternal.sprx is the intended target, and the reviewed head matches the reported 13.42 model. This closes the earlier target question. Source head remains
3d9db7dad635e0290f9e0a2808c593048ecb964d; no additional code or independent console/firmware run is claimed by this documentation update.Tested
Exact tested head:
3d9db7dad635e0290f9e0a2808c593048ecb964d; observed main snapshot:ba5b5330b37724bca4b99f30faab504653635a04. Upstream may advance after that recorded snapshot.Windows 11 / MinGW GCC 15.2 / CMake 4.3.1 and WSL Ubuntu 26.04 / GCC 15.2 / CMake 4.2.3, Release. Configure the actual full project with the existing dependency cache and supported FFMPEG_PREBUILT_DIR option, then build its real shared libc and the repository's
guest_wide_formatting_tests,guest_strftime_tests,guest_time_conversion_testsandguest_time_extras_teststargets. No repository build-file bypass is introduced.^guest_(wide_formatting|strftime|time_conversion|time_extras)$: 4/4 passed on each OS, no skips. The first Windows run exposed the existing default-zone-name assumption; the final exact tests set and restore guest TZ and pass on that same localized host.wcsftime firmware piece units, rather than an import or link failure. The new explicit cases execute on both real shared-library builds.patched_libraries, the remaining libraries/tests, macOS, PS5 hardware, game execution and a new firmware-loader campaign were not run.Current-main conventions with this complete description and whitespace checks pass. Python 3.9 grammar checks pass for changed Python files. Recorded main and the original published PR head are ancestors of this tested branch. Hosted follow-up verified on 2026-10-29 for this same final head
3d9db7dad635e0290f9e0a2808c593048ecb964d: Build run 40867077680 completed with every executed job successful, including full Windows, Linux/Windows/macOS arm64/macOS x86_64 relinker jobs and Linux ASan. The full Linux job was skipped and is not counted as passed. Conventions and the remaining reported checks also pass.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)