Merge pull request #661 from NumberGuan/codex/fix-metadata-download-size

fix(libkernel): preserve 64-bit metadata download sizes
This commit is contained in:
Dean
2026-10-06 08:03:11 +13:00
committed by GitHub
3 changed files with 77 additions and 2 deletions
@@ -1,6 +1,7 @@
#include "prx/libkernel/AppMetadata/include/ParamJsonParser.hpp"
#include <cstdint>
#include <charconv>
#include <filesystem>
#include <fstream>
#include <sstream>
@@ -21,6 +22,7 @@ struct JsonValue {
JsonType type = JsonType::Null;
bool boolValue = false;
double numberValue = 0.0;
std::string numberText;
std::string stringValue;
JsonArray arrayValue;
JsonObject objectValue;
@@ -193,7 +195,8 @@ JsonValue parseJsonNumber(const std::string& text, std::size_t& position) {
}
JsonValue value;
value.type = JsonType::Number;
value.numberValue = std::stod(text.substr(start, position - start));
value.numberText = text.substr(start, position - start);
value.numberValue = std::stod(value.numberText);
return value;
}
@@ -261,7 +264,14 @@ ParsedParamJson parseParamJson(const std::filesystem::path& paramJsonPath) {
result.titleId = titleId;
if (const JsonValue* downloadData = findObjectMember(root, "downloadDataSize")) {
if (downloadData->type != JsonType::Number || downloadData->numberValue < 0) throw std::runtime_error("param.json downloadDataSize is not a size");
result.downloadDataSizeMiB = static_cast<std::uint64_t>(downloadData->numberValue);
if (downloadData->numberText.find_first_of("-.eE") == std::string::npos) {
const auto& number = downloadData->numberText;
const auto parsed = std::from_chars(number.data(), number.data() + number.size(), result.downloadDataSizeMiB);
if (parsed.ec != std::errc{} || parsed.ptr != number.data() + number.size()) throw std::runtime_error("param.json downloadDataSize exceeds uint64 range");
} else {
if (downloadData->numberValue >= 0x1p64) throw std::runtime_error("param.json downloadDataSize exceeds uint64 range");
result.downloadDataSizeMiB = static_cast<std::uint64_t>(downloadData->numberValue);
}
}
return result;
}
+9
View File
@@ -70,6 +70,15 @@ if(MINGW)
endif()
if(BUILD_TESTING)
add_test_executable(param_json_parser_tests ${LIBS_INCLUDE_DIR}/tests/ParamJsonParser.cpp)
target_include_directories(param_json_parser_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(param_json_parser_tests PRIVATE libkernel libc)
configure_windows_unwind(param_json_parser_tests)
add_test(NAME param_json_parser COMMAND param_json_parser_tests)
if(WIN32)
set_tests_properties(param_json_parser PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
endif()
add_test_executable(guest_posix_sem_tests ${LIBS_INCLUDE_DIR}/tests/GuestPosixSem.cpp)
target_include_directories(guest_posix_sem_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_posix_sem_tests PRIVATE libkernel libc)
+56
View File
@@ -0,0 +1,56 @@
#include "prx/libkernel/AppMetadata/include/ParamJsonParser.hpp"
#include <chrono>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <limits>
#include <stdexcept>
#include <string>
#include <utility>
static void Require(bool condition, const std::string& message) {
if (!condition) throw std::runtime_error(message);
}
static ParsedParamJson ParseSize(const std::filesystem::path& path, const std::string& size) {
{
std::ofstream file(path);
file << R"({"titleId":"PPSA00000","localizedParameters":{"en-US":{"titleName":"Example"}})";
if (!size.empty()) file << ",\"downloadDataSize\":" << size;
file << '}';
Require(static_cast<bool>(file), "Cannot write param.json fixture");
}
return parseParamJson(path);
}
int main() {
const auto path = std::filesystem::temp_directory_path() / ("anyps5-param-json-" +
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()) + ".json");
int result = 0;
try {
const std::pair<const char*, std::uint64_t> sizes[] = {
{"", 0}, {"0", 0}, {"-0", 0}, {"4096", 4096},
{"9007199254740993", 9007199254740993ull},
{"18446744073709551614", std::numeric_limits<std::uint64_t>::max() - 1},
{"18446744073709551615", std::numeric_limits<std::uint64_t>::max()},
{"1e3", 1000}, {"1.25", 1}
};
for (const auto& [text, expected] : sizes) {
const auto parsed = ParseSize(path, text);
Require(parsed.downloadDataSizeMiB == expected, std::string("Incorrect download size: ") + text);
Require(parsed.titleId == "PPSA00000" && parsed.title == "Example", "Title metadata changed");
}
for (const auto* text : {"18446744073709551616", "18446744073709551617", "1.8446744073709552e19",
"1e40", "-1", "-0.5", "true", "null", "\"4096\""}) {
bool rejected = false;
try { ParseSize(path, text); } catch (const std::exception&) { rejected = true; }
Require(rejected, std::string("Accepted invalid download size: ") + text);
}
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
result = 1;
}
std::filesystem::remove(path);
return result;
}