feat(libSceNKWebKit): parse decimal numbers as WTF double-conversion #13564
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13564"
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 KernelPanicNT on 2026-10-30T18:28:43Z.
Source of the behaviour
Public WebKit at commit
c55364d53f97(September 2020). The export inventory manglesRefPtr<T, DumbPtrTraits<T>>with two template arguments and usesWTF::AtomString,WTF::Optional,WTF::VariantandJSONImpl. That is the RefPtr.h of this commit; the next commit to that file,b5d72dbcfc24, adds a thirdRefDerefTraitsargument, and5c5f0584738crenamesDumbPtrTraits. The cited parsing code is the same, apart from0becomingnullptr, from theAtomStringrename4da2bec052e0to this commit.okdefaultok/parsedLength, failure returns 0, float overloads arestatic_cast<float>of the doubleVector<LChar>Vectorcapacity aboveUINT_MAXcrashes;CRASH()traps in a release PlayStation build., exponent rewind one,e+,ex), 772 significant digits plus a sticky1, exponent saturating atINT_MAX / 2, no Infinity/NaN/hex; the processed length is written before any character is readintStringToDoubleConverter::StringToDoubleandStringToFloatare static members (nothis),uc16isuint16_tStringToIeeedirectly: no space skipping, code units compared as they are, the processed count written first and set to the parsed lengthStringToFloatis not a cast of the double result:StringToIeee<float>callsStrtof, which rounds the decimal digits to float once, catching double rounding, with the overflow cut at the float midpointAnyPS5 lines replaced:
What
Implements
WTF::charactersToDoubleandWTF::charactersToFloat, all six Latin-1 and UTF-16 overloads (bool* okandsize_t& parsedLength), and the four staticWTF::double_conversion::StringToDoubleConverter::StringToDoubleandStringToFloatoverloads forcharanduint16_tinput, inlibSceNKWebKit, in a newCharactersToNumber.cpp. The library gets aCMakeLists.txtfor the new source and test.StringToIeeestep by step: up to 772 significant digits with a sticky1for dropped nonzero digits, exponent saturation and the rewind to beforeewhen no exponent digits follow. It converts the digits withstd::from_charsinto the result type, which rounds correctly. Overflow and underflow give infinity and zero asStrtodandStrtofdo.StringToDoubleandStringToFloatare that parser as WebKit exports it: no leading-space skipping, the processed count set to 0 first and then to the parsed length, andStringToFloatrounds the digits to float once, asStrtofdoes, so a decimal just above the midpoint between 1 and the next float gives that next float, and one just below the midpoint betweenFLT_MAXand infinity givesFLT_MAX, where a cast of the double result gives 1 and infinity.charactersToDoubleandcharactersToFloataddtoDoubleType: leading ASCII spaces,okandparsedLength. UTF-16 code units above 0x7F map to 0 before parsing, soU+0131orU+0135never read as1or5. The float overloads round through double, the way WebKit does.std::invalid_argument: null characters with a nonzero length, and a nullparsedLengthor processed count. A UTF-16charactersTo*length aboveUINT32_MAXafter the leading spaces throws where WebKit's conversionVectorcrashes. Inputs of about 1 GiB or more whose decimal exponent leaves the range of WebKit'sintthrowstd::overflow_error, since WebKit's result is undefined there.size_t&is modelled as a pointer, as the tree does for references underAPS5_VABI.Functionaldebt entries record the gaps: the exact-power fast path andStrtof's double-to-float cast round in the current rounding mode, and the overflow and crash cases above. The ten rows leave the table of exports that still throw.Open PR #13500 also adds
core/libs/prx/libSceNKWebKit/CMakeLists.txtand edits neighbouring lines ofExport.cpp,InventoryExports.hppand the debt table; it implements none of these ten exports. Whichever merges later rebases. Open PR #13515 also appends todocs/dev/debt/libSceNKWebKit.md, with no shared export.Tested
ctest --test-dir build -R "^guest_nkwebkit_numbers$"passes. Negative controls: withExport.cppandInventoryExports.hpprestored frommainand the new source emptied, the test aborts with_ZN3WTF18charactersToDoubleEPKhmPb not implemented; with the three files as they were before the fourStringToDoubleConverterexports were added, it aborts with_ZN3WTF17double_conversion23StringToDoubleConverter14StringToDoubleEPKcmPm not implemented. WithStringToFloatchanged to a cast of the double result, the float rounding checks fail.libSceNKWebKit.prxexports the ten names, and each one points at the new function.StringToIeee,Strtod,Strtof,Bignum,DiyFpand cached powers from the pinned commit, built on the host with the WTF wrappers copied as written, against this implementation. For the sixcharactersTo*overloads, millions of inputs (random strings over digits, signs,.,e, ASCII and non-ASCII spaces, bytes above 0x7F, long and short UTF-16, midpoints between adjacent doubles printed with up to 800 digits, denormal and overflow boundaries, 700 to 1500 digit inputs, exponents beyondINT_MAX / 2) gave bit-identical values,okandparsedLength. For the fourStringToDoubleConverterexports, 8 million inputs of the same kinds plus exact midpoints between adjacent floats and their neighbouring doubles, float denormal andFLT_MAXboundaries, and code units such asU+0131andU+0165gave bit-identical values and processed counts. A 1 GiB input on each side of theintexponent limit returns infinity and throwsstd::overflow_errorrespectively.python3 tools/check_conventions.py --base origin/mainpasses.tools/progress.py --compare: +10 implemented functions in libSceNKWebKit.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)