Skip to content

Commit

Permalink
More validation
Browse files Browse the repository at this point in the history
Reviewed By: ssj933

Differential Revision: D57176819

fbshipit-source-id: dbe31f4464a57aff7b011c38ab5b523b0c0d33e8
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed May 10, 2024
1 parent a93afe1 commit f5d59bd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libredex/JarLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ namespace {

DexType* parse_type(std::string_view& buf) {
char typebuffer[MAX_CLASS_NAMELEN];
always_assert(!buf.empty());
char desc = buf.at(0);
buf = buf.substr(1);
switch (desc) {
Expand All @@ -312,10 +313,12 @@ DexType* parse_type(std::string_view& buf) {
case 'L': {
char* tpout = typebuffer;
*tpout++ = desc;
always_assert(!buf.empty());
while (buf.at(0) != ';') {
*tpout++ = buf[0];
buf = buf.substr(1);
}
always_assert(!buf.empty());
*tpout++ = buf.at(0);
buf = buf.substr(1);
*tpout = '\0';
Expand All @@ -325,14 +328,17 @@ DexType* parse_type(std::string_view& buf) {
case '[': {
char* tpout = typebuffer;
*tpout++ = desc;
always_assert(!buf.empty());
while (buf.at(0) == '[') {
*tpout++ = buf[0];
buf = buf.substr(1);
always_assert(!buf.empty());
}
if (buf.at(0) == 'L') {
while (buf.at(0) != ';') {
*tpout++ = buf[0];
buf = buf.substr(1);
always_assert(!buf.empty());
}
*tpout++ = buf.at(0);
buf = buf.substr(1);
Expand All @@ -349,6 +355,7 @@ DexType* parse_type(std::string_view& buf) {
}

DexTypeList* extract_arguments(std::string_view& buf) {
always_assert(buf.size() >= 2);
buf = buf.substr(1);
if (buf.at(0) == ')') {
buf = buf.substr(1);
Expand All @@ -363,6 +370,7 @@ DexTypeList* extract_arguments(std::string_view& buf) {
return nullptr;
}
args.push_back(dtype);
always_assert(!buf.empty());
}
buf = buf.substr(1);
return DexTypeList::make_type_list(std::move(args));
Expand Down

0 comments on commit f5d59bd

Please sign in to comment.