feat(libSceIcu): implement the resource bundle accessors #24288
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24288"
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 larpsahur333 on 2026-11-20T13:07:02Z.
What
Twelve
libSceIcuexports that answeredNotImplemented_nid_no_patchnow read the bundle:ures_getKey- the key pointer at offset 0ures_getType- the resource word at offset 172, type in the top four bits, with reserved type 15 reported asURES_NONEures_getSize- the item count at offset 196ures_hasNext- the iterator index at offset 192 against the sizeures_getString- checks the type, followsfResData.pRootat offset 48, reads the unit count that prefixes the string and returns the units past itures_getInt- reads the value out of an integer resource wordures_getIntVector- returns the length-prefixed vector past its prefixures_getBinary- returns the length-prefixed bytes past their prefixures_getLocaleByType- returns the actual (offset 8) or valid (offset 24) locale nameures_getByKey- finds a table entry by key, comparing the table's pool strings through a bounded guest read, and fills the caller's bundle with the found resourceures_getByIndex- returns an array item by index and fills the caller's bundleures_getStringByKey- looks the entry up into a stack bundle zeroed withures_initStackObject, then delegates the string read toures_getStringThe layout is the ICU 68.2
UResourceBundlefromuresimp.htogether with theResourceDataat offset 40: 200 bytes,pRootat 48,fResat 172,fIndexat 192,fSizeat 196. Every field is copied throughGuestCopyInbefore it is read, and the child bundle and every out-parameter are written throughGuestCopyOut.ures_getByKeycopies the caller's key and every pool key throughReadGuestString, which reads one byte perCopyIninto a 256-byte buffer and accepts at most 254 characters plus the terminator; a longer or unterminated caller key fails withU_ILLEGAL_ARGUMENT_ERRORand a pool key that does not terminate inside the cap is skipped.Still unsupported: pool bundles report
U_UNSUPPORTED_ERROR, fallback chains are not searched so a missing key reportsU_MISSING_RESOURCE_ERROR, and table-by-index reportsU_RESOURCE_TYPE_MISMATCH. The by-key string path sharesures_getString's limits, so type-6 pool-bundle strings and fallback chains stay unsupported there too.Tested
guest_icu_resource_accessors(core/libs/prx/libSceIcu/tests/ResourceAccessors.cpp) passes. It builds synthetic 200-byte bundles and resource pools, so noicudtdata is needed:ures_hasNextreports a following item at index 1, none at index 2, and one at index 0URES_NONEand type 0 reports a stringures_getStringreturns the pool units past the length prefix (the pointer offset is asserted, not just the contents), reports the length, rejects an integer resource with a type mismatch and a null bundle with an illegal argumentures_getByKeyfinds a two-entry table, returns the integer 7 fromures_getInt, returns the key pointer and the string entry, and reportsU_MISSING_RESOURCE_ERRORfor a missing key andU_ILLEGAL_ARGUMENT_ERRORfor a null fill-inures_getByKeyrejects a 300-character caller key withU_ILLEGAL_ARGUMENT_ERROR, and skips a pool key with no NUL inside the 254-character cap so the lookup reportsU_MISSING_RESOURCE_ERRORures_getStringByKeyreturns the table's string entry unit by unit (u'h',u'i') with its length, rejects the integer entry withU_RESOURCE_TYPE_MISMATCH, reportsU_MISSING_RESOURCE_ERRORfor a missing key, and answers null for a null status without writing through itures_getByIndexreturns 11, 22 and 33 from a three-integer array, reports the scalar child size, and rejects an out-of-range index and a tableURES_NONE, 0 and false respectivelyChecklist
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 repositoryImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:15:03Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: route guest output writes through
CopyOutso invalid guest pointers are handled safely.What I ran
Reviewed head
dcb8ac8b5f166c9f3ebb5753c69b73bb74e6d04fusing the pinnedrepo_read.pyreader. I did not run build or test commands; no merged-preview check was run.Results
Negative control
Not run; no test was run to confirm that an invalid guest output pointer fails safely.
Findings
Blocking
core/libs/prx/libSceIcu/ResourceBundle.cpp:197writes directly through the guestlengthpointer before usingCopyOutat line 239. The same direct write occurs in the string, vector, and binary accessors. An invalid guest pointer can therefore fault the host process before the guarded copy handles it. Remove the direct writes and useCopyOutfor each length output, including initialization to zero.Non-blocking
None.
Sources
Not verified
The build, test results, and runtime behavior on a physical console were not verified. Read:
core/libs/prx/libSceIcu/CMakeLists.txt,core/libs/prx/libSceIcu/LegacyExports.cpp(changed regions),core/libs/prx/libSceIcu/RecoveredSignatures.hpp,core/libs/prx/libSceIcu/ResourceBundle.cpp,core/libs/prx/libSceIcu/include/LegacyExports.hpp(header beginning; the diff’s removed declarations were reviewed),core/libs/prx/libSceIcu/tests/ResourceAccessors.cpp, anddocs/dev/debt/changes/feat-libsceicu-ures-accessors.md. No changed files were excluded by the prepared manifest.To get this to a good state
Use
CopyOutfor every write throughlength, including the initial zero value, then rerun the accessor test and relevant build checks on the updated head.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T13:55:04Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
3176b51874:tools/check_conventions.pypassed.guest_icu_resource_accessors_testsbuilt cleanly.guest_icu_resource_accessors):core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/RecoveredSignatures.hpp,core/libs/prx/libSceIcu/ResourceBundle.cpp,core/libs/prx/libSceIcu/include/LegacyExports.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:59:56Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix
ures_hasNextso it reports an item whenever the current index is below the bundle size.What I ran
Reviewed head
3176b51874343e7642b425ffecb6d0e483c8b616using the prepared diff andrepo_read.pyfor targeted source context. No tests were run.Results
Findings
Blocking
core/libs/prx/libSceIcu/ResourceBundle.cpp:127usesindex < size - 1. With a size of 3 and index 2, this returns false even though the current index is still within the bundle; the test explicitly enshrines that incorrect boundary atcore/libs/prx/libSceIcu/tests/ResourceAccessors.cpp:45. Useindex < sizeinstead, and cover the final valid index. This causes iteration to stop before the last item.Non-blocking
Not verified
No tests or build were run. Read the prepared description, commits, manifest and diff, plus the full included changed files
core/libs/prx/libSceIcu/ResourceBundle.cpp,core/libs/prx/libSceIcu/tests/ResourceAccessors.cpp,core/libs/prx/libSceIcu/CMakeLists.txt,core/libs/prx/libSceIcu/RecoveredSignatures.hpp, anddocs/dev/debt/changes/feat-libsceicu-ures-accessors.md. Also read targeted ranges incore/libs/prx/libc/src/General.cpp,core/libs/prx/libSceIcu/Export.cpp, andcore/libs/prx/libSceIcu/tests/ResourceUInt.cpp.LegacyExports.cppandinclude/LegacyExports.hppwere present in the manifest but their full texts were not read; their relevant declaration/removal hunks were inspected in the diff. No changed files were excluded according to the manifest.To get this to a good state
Correct the iterator boundary and update the final-valid-index test; then run the resource accessor test on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T14:18:15Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The child bundle copies a pointer from the parent’s resource data, so children of non-root bundles can resolve resources through the wrong pool.
What I ran
Reviewed head
a042bc33c38a77019728095b81bc0cbe9f2e3166. I read the prepared description, commits, manifest, and diff; inspected the implementation, signatures, and test source at the pinned head. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libSceIcu/ResourceBundle.cpp:81-84copies the parent’sfResDataintofillIn, but does not replace the copiedpRootwith therootargument used to find the child. When a parent bundle is itself a child and has different resource data, the returned child bundle keeps the parent’s root; later accessors such asures_getStringread its resource offset against that root. Copy the correct resource data for the resolved child, including its root, before returning it.Non-blocking
Not verified
ResourceBundle.cpp,RecoveredSignatures.hpp, andtests/ResourceAccessors.cpp; the prepared diff was read for the remaining changed files. The full text ofCMakeLists.txt,Export.cpp,LegacyExports.cpp,InventoryExports.hpp,LegacyExports.hpp, anddocs/dev/debt/changes/feat-libsceicu-ures-accessors.mdwas not inspected.To get this to a good state
Update
FillChildso the child bundle receives the correct resource data and root for its resolved resource, then rerun the accessor test and review the new head.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T14:20:29Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
a042bc33c3:tools/check_conventions.pypassed.guest_icu_resource_accessors_testsbuilt cleanly.guest_icu_resource_accessors):core/libs/prx/libSceIcu/Export.cpp,core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/RecoveredSignatures.hpp,core/libs/prx/libSceIcu/ResourceBundle.cpp,core/libs/prx/libSceIcu/include/InventoryExports.hpp,core/libs/prx/libSceIcu/include/LegacyExports.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.index < size - 1 ? 1 : 0. When iterating over a bundle, index represents the 0-based position of the next element; the last valid element has indexsize - 1. Testingindex < size - 1returns 0 (false) when index == size - 1, prematurely halting iteration before visiting the last item. It must checkindex < size(orindex >= 0 && index < size).Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T14:54:07Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix unsafe key-string traversal in table lookup.
What I ran
Reviewed head
d9aecf8d338a220cadabc334f440720d1339fac9from the prepared diff and pinned reader. No build or test command was run.Results
Findings
Blocking
ures_getByKeypasses the bundle key directly tostd::strcmpand derives a table key pointer from the pool offset without validating either string is NUL-terminated and in bounds. With malformed or untrusted bundle data, comparison can read beyond the guest pool and potentially crash the host process. Use bounded guest reads and validate offsets/termination before comparing. (core/libs/prx/libSceIcu/ResourceBundle.cpp:534)Non-blocking
None.
Not verified
No build or tests were run. The included test source and docs were read.
Export.cpp,LegacyExports.cpp,RecoveredSignatures.hpp,include/InventoryExports.hpp, andinclude/LegacyExports.hppwere listed in the manifest but their full contents were not read. No files were excluded by the provided file listing.To get this to a good state
Validate table key offsets and bounded string contents before comparing them in
ures_getByKey, then rerun the targeted accessor test and build.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T15:06:15Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d9aecf8d33:tools/check_conventions.pypassed.guest_icu_resource_accessors_testsbuilt cleanly.guest_icu_resource_accessors):core/libs/prx/libSceIcu/Export.cpp,core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/RecoveredSignatures.hpp,core/libs/prx/libSceIcu/ResourceBundle.cpp,core/libs/prx/libSceIcu/include/InventoryExports.hpp,core/libs/prx/libSceIcu/include/LegacyExports.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.ures_hasNextchecksreturn index < size - 1 ? 1 : 0;. When iterating a bundle withsizeelements, indices0throughsize - 1are valid elements. Ifindex == size - 1(the last element),index < size - 1evaluates tofalse(0), prematurely indicating no more elements before reading the final element. It should bereturn index < size ? 1 : 0;.ures_getByKey,std::strcmp(key, keyText)dereferenceskeyText = reinterpret_cast<const char*>(root + keyOffset)directly in host memory without verifying thatkeyTextorroot + keyOffsetis within the guest allocated resource bounds or null-terminated, creating potential out-of-bounds guest memory reads on malformed bundle data.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T15:39:10Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
cc0ac93e56:tools/check_conventions.pypassed.guest_icu_resource_accessors_testsbuilt cleanly.guest_icu_resource_accessors):core/libs/prx/libSceIcu/Export.cpp,core/libs/prx/libSceIcu/LegacyExports.cpp,core/libs/prx/libSceIcu/RecoveredSignatures.hpp,core/libs/prx/libSceIcu/ResourceBundle.cpp,core/libs/prx/libSceIcu/include/InventoryExports.hpp,core/libs/prx/libSceIcu/include/LegacyExports.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T15:39:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: remove the fixed key-length limitation so valid table entries are not reported missing.
What I ran
cc0ac93e56ef699861ac3d5fb5c4ae307653ea56; basemainwas not merged or checked.description.md,commits.md,manifest.json,diff.patch,ResourceBundle.cpp,InventoryExports.hpp,InventoryDispatch.hpp, and the relevantCMakeLists.txtsection. All changed files were included in the bundle; I read the implementation but not the full test source or other changed files.repo_read.py.Results
Findings
Blocking
core/libs/prx/libSceIcu/ResourceBundle.cpp:437: Table key comparison reads each candidate into a 256-byte buffer. Keys that do not terminate within that buffer are skipped at line 438, causing a valid key lookup to returnU_MISSING_RESOURCE_ERROR. Read candidate keys without imposing this limit, or compare incrementally against the requested key.Non-blocking
None.
Not verified
guest_icu_resource_accessorspasses.CMakeLists.txt,Export.cpp,LegacyExports.cpp,RecoveredSignatures.hpp,InventoryExports.hpp,LegacyExports.hpp, ortests/ResourceAccessors.cpp.To get this to a good state
Support valid table keys longer than 255 bytes, add coverage for a long key, and rerun the resource accessor test on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:22:23Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: preserve the caller’s bundle status on successful lookups and avoid reporting a missing resource when the key pointer is null.
What I ran
Reviewed head
e4bb2d8cd252493d16ba5a9afb04aeab671caf75. I read the prepared description, commits, manifest, diff, and all included changed files; I also inspected the relevantResourceBundle.cppcontext and export declarations. No tests or build commands were run.Results
Findings
Blocking
core/libs/prx/libSceIcu/ResourceBundle.cpp:451andcore/libs/prx/libSceIcu/ResourceBundle.cpp:485: successfulures_getByKeyandures_getByIndexcalls never write the caller’s status. ICU’s status convention requires successful calls to leave a pre-existing warning status unchanged; however,FillChilddoes not receive or update the status, and the tests only check success when status starts at zero. Confirmed other accessors preserve warning status by returning early only for positive errors, so a nonzero warning remains intact there.core/libs/prx/libSceIcu/ResourceBundle.cpp:418: a null key is reported asU_MISSING_RESOURCE_ERROR, although it is an invalid argument. This makes invalid input indistinguishable from an absent table entry; returnU_ILLEGAL_ARGUMENT_ERRORfor null key.Non-blocking
None.
Not verified
No build or tests were run. No runtime behavior on a physical console was verified.
review/files.jsonwas not available as a readable document; the reader’s file listing identified eight changed files, all marked included, and the manifest lists those same changes.To get this to a good state
Fix the null-key status and add coverage for null keys and successful lookups with a warning status. Rerun the
guest_icu_resource_accessorstest on the updated head.Pull request closed