feat(libSceFreeTypeOt): implement the FreeType stream calls #12473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12473"
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 simnJS on 2026-10-28T15:10:08Z.
What
Implements the 36 FreeType stream calls that libSceFreeTypeOt exports and
maindeclares assceFreeTypeOtUnknown_*throwing aliases. #12457 found their names withtools/nid_names.py; each NID below iscompute_nidof its name.FT_Stream_OpenMemory,FT_Stream_Close,FT_Stream_Seek,FT_Stream_Skip,FT_Stream_Pos,FT_Stream_Read,FT_Stream_ReadAt,FT_Stream_TryReadFT_Stream_EnterFrame,FT_Stream_ExitFrame,FT_Stream_ExtractFrame,FT_Stream_ReleaseFrame,FT_Stream_ReadFieldsFT_Stream_GetChar,GetShort,GetShortLE,GetUShort,GetUShortLE,GetOffset,GetUOffset,GetLong,GetLongLE,GetULong,GetULongLEFT_Stream_ReadChar,ReadShort,ReadShortLE,ReadUShort,ReadUShortLE,ReadOffset,ReadUOffset,ReadLong,ReadLongLE,ReadULong,ReadULongLEFT_Stream_FreeReference: FreeType 2.4.12
src/base/ftstream.c(L34-L862) andFT_Stream_Free; the record and frame-field layouts areftsystem.handinternal/ftstream.h. The PS5 3.20 inventory holds both the signedGetShort/GetOffset/GetLong/ReadShort/ReadOffset/ReadLong(+LE) readers and the unsigned ones that replaced them in 2.4.5 (21b1a0de7c); the signed ones follow 2.4.4ftstream.c, whose bodies differ from 2.4.12 only in the signedFT_NEXT_*macros. The bodies are unchanged through 2.10.4 apart from return types, so the result does not depend on which of those versions the console built.GuestStreamRecis the LP64FT_StreamRec(80 bytes:unsigned longsize and position, pointer descriptors),GuestFrameFieldisFT_Frame_Field(4 bytes); both are asserted. The allocator record is libSceFreeType's existingGuestMemoryRec. Read, close, allocation and release callbacks are guest functions, called with the guest stream or memory record as FreeType does.pos + n < sizeandpos + distancewrap asunsigned long, frame bounds are pointer comparisons, frame allocation passescountas a signedFT_Long(so a count aboveLONG_MAXgivesInvalid_Argument), and a short device frame read releases the block, leavescursornull andlimitatcount, and still advances the position. A memory stream with a null base reads 0 at position 0 as FreeType'sif ( p )does.FT_Stream_ReadFieldsreads integer fields without a frame bound check and stores them by field size (1, 2, 4, otherwise 8 bytes), sign-extending through 32 bits.std::invalid_argument, and it does so before anything is acquired or moved:FT_Stream_ExtractFramechecks its output pointer before entering the frame, a frame allocation needs the allocator and release callbacks before it allocates (FreeType would call the null release onFT_Stream_ExitFrame),FT_Stream_ReadFieldsexits a frame it entered before refusing a null structure or cursor, andFT_Stream_Freechecks the release callback before callingclose.FT_Stream_ReadFieldswith a null stream and non-null fields also throws: it returnsInvalid_Argumentup to 2.5.3 andInvalid_Stream_Handlefrom 2.5.4 (0d4aa23e7).Export.cpp; the functions are defined asFT_Stream_*_nid_postfixinlibSceFreeTypeOt/Stream.cpp, so the patched module exports them under the same NIDs. Declarations and layouts are inlibSceFreeTypeOt/include/Stream.hpp, included bylibSceFreeTypeOt.hpp. The sources and tests come in throughStream.cmake, oneincludeline in the library'sCMakeLists.txt, placed where none of the open pull requests on that file edits.FT_Stream_New(needs the library object andFT_Open_Args) andFT_Stream_Open(opens a host file) still throw. An entry under Unknown function info records the version and null-pointer gaps. TheThe 129 sceFreeTypeOtUnknown_*count line is left as it is: many open pull requests edit that line (it is already 126 onmain).Landing order with #12370. #12370 (kyon-eth) keeps the 36
sceFreeTypeOtUnknown_*stream aliases this PR removes, and itsCMakeLists.txtandlibSceFreeTypeOt.hpppredateStream.cmakeandStream.hpp. Nothing competes (none of its 68 forwards or 96 declarations is a stream export), but a textual merge of the two heads keeps 20 of the aliases next to the implementations, so the second to land must reconcileExport.cpp. Agreed with kyon-eth (acceptance on #12370, confirmation here): this PR lands first; #12370 declaresDepends on: #12473and, once this lands, rebases to keepStream.cmakeandStream.hppand drop the 36 stream aliases.tools/progress.py: libSceFreeTypeOt 2/148 → 38/148; all libraries 6627/14197 (46.68 %) → 6663/14197 (46.93 %).Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 (x86_64-ucrt-posix-seh), Release,
BUILD_TESTING=ON, rebased onmain17f8dfad51. No title run.guest_freetype_streamandguest_freetype_stream_patched: the same cases run against the rawlibSceFreeTypeOt.prx(resolvingFT_Stream_*_nid_postfix) and the NID-patched one (resolving the 36 NIDs). They cover:OpenMemoryfields (limit, memory, descriptor and path name untouched), seek to the end and past it, negative skip with a null stream, skip that wrapsunsigned long,PosofULONG_MAXas -1, full, short and past-the-endReadAt/Read/TryRead, null buffers with and without bytes;ExtractFrame/ReleaseFrame, everyGet*value (signed and unsigned, big- and little-endian, 1/2/3/4 bytes) and the no-frame and null-cursor cases;Read*value, the bounds (pos + n - 1 >= size), a position ofULONG_MAXthat wraps to readbase - 1, a null base at position 0 (reads 0) and past it (throws), a null error pointer;read(stream, pos, NULL, 0)without a size check, callback arguments, short reads, frame allocation through the guest allocator, allocation failure (Out_Of_Memory, base cleared), a short frame read (block released,limitleft atcount), an empty frame with no allocator, a count aboveLONG_MAX(Invalid_Argument),ReadCharignoring the size,Close, andFT_Stream_Freereadingmemorybefore the close callback clears it, closing before releasing, and not releasing an external stream;ReadFields: every integer operation with 1-, 2-, 4- and 8-byte stores and sign extension, skip, byte sequences, a sequence past the frame, an integer read past the frame, an unknown operation ending the list, a failing frame start, a device frame released on exit, null fields (Invalid_Argument), null stream and null structure (throw);ExtractFramewith a null output on a memory and a device stream (no allocation, no read, no release,base,pos,cursorandlimitunchanged), a frame with an allocator but no release callback (refused before allocating or reading; an empty frame and a frame larger than the stream still answer without it),ReadFieldsrefusing a null structure inside a device and a memory frame (the frame is released and exited first),FT_Stream_Freewithout a release callback (refused beforeclose).ctest -R freetype: libSceFreeType, libSceFreeTypeOl and libSceFreeTypeOt, raw and patched) pass, 5 runs each (--repeat until-fail:5). Mutation check: 12 single-line changes toStream.cppeach make the raw test fail (the 8 listed in the first revision, plus undoing each of the four refusal-order fixes).main's library (same test executable): the raw run fails withmissing stream export, the patched run aborts withsceFreeTypeOtUnknown_a7RlARfexoo_nid_no_patch not implemented.public_headers,public_headers_compile_*,conventions_*,test_registration,test_script_registration: 107/107 pass. The new files build without warnings.python tools/check_conventions.py --base origin/mainwith this title and body: all checks pass.git merge-treeof this branch with its head gives exactly the conflicts it already has withmain, and no new one. #12370 needs the reconciliation described above.fe446f1a1d, merged intomain): Windows run 40720082916 (upstreambuild.yml, full), 2842/2842 tests pass; Linux run 40720087392 (Ubuntu 24.04, lavapipe), 2726/2726 tests pass.guest_freetype_streamandguest_freetype_stream_patchedpass in both.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T15:11:36Z.
Review: CHANGES_REQUESTED
I found one blocking cleanup issue in
FT_Stream_ExtractFrame; the rest of this review is limited to the finding below. The branch also still needs review against the latestmainhead17f8dfad513b134a4996991109fc9db47a3bb905before merge, though its current merge tree is clean.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:19:28Z.
Review: APPROVED
Re-checked — approved
The latest head
fe446f1a1dc1e2fb6b640ec08b34b42b7abfe906fixes theFT_Stream_ExtractFramecleanup path: the output pointer is validated before frame acquisition, and the new memory/device cases check that failure does not change stream position or leak/release frame state. The additional allocator,ReadFields, andFT_Stream_Freefailure-path regressions are also included. The author reports both raw and NID-patched stream test executables passing on Windows.The #12370 author has now confirmed #12473 first and recorded
Depends on: #12473on #12370; I independently found no duplicateFT_Stream_*provider in the other named export patches. The branch is mergeable against current main; although main has advanced since the last refresh, none of this PR’s touched files changed on main in the interim. Hosted Windows, conventions, labels, and eligibility checks pass. I did not run the stream tests locally.