Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions core/libs/prx/libSceNKWebKit/src/WtfPrimitives.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "prx/libc/include/General.hpp"
#include "prx/libc/include/general/VabiMacros.hpp"
#include "prx/libSceNKWebKit/include/WtfExports.hpp"
#include "prx/libSceIcu/Version.hpp"
Expand All @@ -22,6 +23,12 @@ const std::array<std::uint8_t, 4>& GetIcuVersion() {
return version;
}

unsigned char HashCharacter(const char* data, unsigned index) {
unsigned char character = 0;
if (!GuestCopyIn_nid_no_patch(&character, data + index, sizeof(character))) throw std::invalid_argument("unreadable WTF six-character hash");
return character;
}

} // namespace

extern "C" {
Expand Down Expand Up @@ -49,15 +56,15 @@ unsigned APS5_VABI _ZN3WTF31sixCharacterHashStringToIntegerEPKc(const char* data
if (!data) throw std::invalid_argument("null WTF six-character hash");
unsigned hash = 0;
for (unsigned i = 0; i < 6; ++i) {
unsigned c = static_cast<unsigned char>(data[i]);
unsigned c = HashCharacter(data, i);
unsigned value;
if (c >= 'A' && c <= 'Z') value = c - 'A';
else if (c >= 'a' && c <= 'z') value = c - 'a' + 26;
else if (c >= '0' && c <= '9') value = c - '0' + 52;
else throw std::invalid_argument("invalid WTF six-character hash");
hash = hash * 62 + value;
}
if (data[6]) throw std::invalid_argument("WTF hash must contain six characters");
if (HashCharacter(data, 6)) throw std::invalid_argument("WTF hash must contain six characters");
return hash;
}

Expand Down
1 change: 1 addition & 0 deletions core/libs/prx/libSceNKWebKit/tests/Wtf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,7 @@ void TestPrimitiveState() {
Throws([&] { SixHash("short"); });
Throws([&] { SixHash("AAAAAAA"); });
Throws([&] { SixHash("AAAAA!"); });
Throws([&] { SixHash(reinterpret_cast<const char*>(std::uintptr_t{0x10})); });
for (std::uint8_t type = 0; type < 10; ++type) {
Check(IsReload(type) == (type == 4 || type == 8 || type == 9));
Check(IsBackForward(type) == (type >= 1 && type <= 3));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libSceNKWebKit

## add Functional

- [WTF::sixCharacterHashStringToInteger](../../../core/libs/prx/libSceNKWebKit/src/WtfPrimitives.cpp) (libSceNKWebKit) reads the hash's characters and its terminator one at a time with `GuestCopyIn_nid_no_patch`, stopping at the first invalid one as before, so a string that can't be read throws `std::invalid_argument`, as a null or malformed one does. This is a host-safety fallback; the console's behaviour for an inaccessible string is not measured.
Loading