mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(json2): throw on numbers that overflow a double
Whether the console's parser rejects 1e309 or stores an infinite real is unknown, and RFC 8259 allows both. Following the exact-or-throw rule, sce::Json::Parser::parse now throws with the number text and a note that the behaviour is unverified, instead of returning JsonErrorParse. The partially built tree is freed before the exception leaves the parser. The case is listed under unknown function info in TechnicalDebt.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R5WJS4ZdQynAJesCZKH5hb
This commit is contained in:
@@ -372,7 +372,7 @@ private:
|
||||
}
|
||||
}
|
||||
const double real = std::strtod(text.c_str(), nullptr);
|
||||
if (!std::isfinite(real)) return false;
|
||||
if (!std::isfinite(real)) throw std::runtime_error("sce::Json::Parser::parse: number " + text + " overflows a double; the console's behaviour is unverified");
|
||||
out.type = TypeReal;
|
||||
out.real = real;
|
||||
return true;
|
||||
@@ -734,7 +734,14 @@ int APS5_VABI _ZN3sce4Json6Parser5parseERNS0_5ValueEPKcm(Value* out, const char*
|
||||
if (text == nullptr) throw std::invalid_argument("sce::Json::Parser::parse: null text");
|
||||
Node parsed{};
|
||||
Parser parser(text, size);
|
||||
if (!parser.Parse(parsed)) {
|
||||
bool parsedOk = false;
|
||||
try {
|
||||
parsedOk = parser.Parse(parsed);
|
||||
} catch (...) {
|
||||
Clear(parsed);
|
||||
throw;
|
||||
}
|
||||
if (!parsedOk) {
|
||||
Clear(parsed);
|
||||
return JsonErrorParse;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -163,10 +164,20 @@ static void ParseAndRoundTrip() {
|
||||
Require(Serialize(reparsed) == serialized);
|
||||
_ZN3sce4Json5ValueD1Ev(&reparsed);
|
||||
|
||||
for (const char* invalid : {"{\"a\":}", "[1,]", "\"open", "tru", "{} x", "01", "1e309", "[-1e309]", "{\"a\":1e400}"}) {
|
||||
for (const char* invalid : {"{\"a\":}", "[1,]", "\"open", "tru", "{} x", "01"}) {
|
||||
Require(_ZN3sce4Json6Parser5parseERNS0_5ValueEPKcm(&root, invalid, std::strlen(invalid)) < 0);
|
||||
Require(_ZNK3sce4Json5Value7getTypeEv(&root) == TypeObject && _ZNK3sce4Json5Value5countEv(&root) == 8);
|
||||
}
|
||||
for (const char* overflow : {"1e309", "[-1e309]", "{\"a\":[1,1e400]}"}) {
|
||||
bool unverified = false;
|
||||
try {
|
||||
_ZN3sce4Json6Parser5parseERNS0_5ValueEPKcm(&root, overflow, std::strlen(overflow));
|
||||
} catch (const std::runtime_error& error) {
|
||||
unverified = std::string(error.what()).find("unverified") != std::string::npos;
|
||||
}
|
||||
Require(unverified);
|
||||
Require(_ZNK3sce4Json5Value7getTypeEv(&root) == TypeObject && _ZNK3sce4Json5Value5countEv(&root) == 8);
|
||||
}
|
||||
_ZN3sce4Json5ValueD1Ev(&root);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [sceFontGetPixelResolution](../../core/libs/prx/libSceFont/src/Library.cpp) (libSceFont) - signature taken from the IDA type database of [Orbital](https://github.com/AlexAltea/orbital/blob/master/tools/ida/db_types.json), not confirmed on a title. The value is the one the library's driver reports (64 for FreeType); the argument checks and the cleared output follow `sceFontGetLibrary`
|
||||
- [sceFontCreateWritingLine, sceFontWritingLineWritesOrder](../../core/libs/prx/libSceFont/src/WritingLine.cpp) (libSceFont) - signatures and the `SceFontWritingLineStep`/`SceFontCreateWritingLineDetail` layouts (detail id `0x0FD5`) taken from [SharpProspero](https://github.com/SvenGDK/SharpProspero/blob/main/src/SharpProspero/Interop/Font/SceFontStructs.cs), not confirmed on a title; the meaning of the 64-bit writing attribute is unknown
|
||||
- [sceSaveDataTransferringMountPs4, sceSaveDataDirNameSearchPs4](../../core/libs/prx/libSceSaveData.native/Export.cpp) (libSceSaveData.native) - arguments assumed to be those of `sceSaveDataTransferringMount` and `sceSaveDataDirNameSearch`: KytyPS5 binds both NIDs to the PS5 functions, and [prosper](https://github.com/mattias800/prosper) captured the same result layout on a title for the search. There is no PS4 save area, so the mount returns `NOT_FOUND` and the search reports zero hits
|
||||
- [sce::Json::Parser::parse](../../core/libs/prx/libSceJson2/Export.cpp) (libSceJson2) - a number that overflows a double (e.g. `1e309`) throws: whether the console rejects the document or stores an infinite real is unknown
|
||||
- [sceAgcSetSubmitMode](../../core/libs/prx/libSceAgc/Misc/src/Suspend.cpp) (libSceAgc) - mode values unknown; only 0 is accepted
|
||||
- [SET_PREDICATION](../../core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp) (AGC driver) - boolean predication follows the AMD PM4 encoding [Mesa](https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/amd/common/sid.h) uses: operation 3 reads 64 bits and 4 reads 32 bits, and bit 8 runs predicated packets when the value is non-zero (clear: when it is zero); the bit 12 hint is ignored. The address must have its low 4 bits clear, as `sceAgcDcbSetPredication` writes it. Query predication (Z-pass, primitive count), a predicated COND_EXEC, predicated command buffer chains and flips in predicated command buffers throw
|
||||
- [sceAgcGetGsOversubscription](../../core/libs/prx/libSceAgc/Shader/src/GsOversubscription.cpp) (libSceAgc) - signature and occupancy formula (base and expanded vertex/export capacities, budget shift, `GE_PC_ALLOC` / `SPI_SHADER_PGM_RSRC4_GS` encoding) follow KytyPS5 only, not confirmed on hardware or a title; a negative or NaN factor that gives a negative target, a missing GS context register or a zero `GE_MAX_OUTPUT_PER_SUBGROUP` throws
|
||||
|
||||
Reference in New Issue
Block a user