Skip to content

Commit

Permalink
Handle std::invalid_argument exception in make_dextype_from_cref
Browse files Browse the repository at this point in the history
Reviewed By: agampe

Differential Revision: D52610343

fbshipit-source-id: fa89a2e30b61903ac0cc0c2d838445b7a7108b5d
  • Loading branch information
Wei Zhang (Devinfra) authored and facebook-github-bot committed Jan 9, 2024
1 parent bcde2a4 commit c6528f4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions libredex/JarLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ DexType* make_dextype_from_cref(std::vector<cp_entry>& cpool, uint16_t cref) {
std::cerr << "classname is greater than max, bailing";
return nullptr;
}
nbuffer[0] = 'L';
memcpy(nbuffer + 1, utf8cpe.data, utf8cpe.len);
nbuffer[1 + utf8cpe.len] = ';';
nbuffer[2 + utf8cpe.len] = '\0';
return DexType::make_type(nbuffer);
try {
nbuffer[0] = 'L';
memcpy(nbuffer + 1, utf8cpe.data, utf8cpe.len);
nbuffer[1 + utf8cpe.len] = ';';
nbuffer[2 + utf8cpe.len] = '\0';
return DexType::make_type(nbuffer);
} catch (std::invalid_argument&) {
return nullptr;
}
}

bool extract_utf8(std::vector<cp_entry>& cpool,
Expand Down Expand Up @@ -483,7 +487,7 @@ bool parse_class(uint8_t* buffer,
cc.set_external();
if (super != 0) {
DexType* sclazz = make_dextype_from_cref(cpool, super);
if (self == nullptr) {
if (sclazz == nullptr) {
std::cerr << "Bad super class cpool index " << super << ", Bailing\n";
return false;
}
Expand All @@ -494,6 +498,10 @@ bool parse_class(uint8_t* buffer,
for (int i = 0; i < ifcount; i++) {
uint16_t iface = read16(buffer, buffer_end);
DexType* iftype = make_dextype_from_cref(cpool, iface);
if (iftype == nullptr) {
std::cerr << "Bad interface cpool index " << super << ", Bailing\n";
return false;
}
cc.add_interface(iftype);
}
}
Expand Down

0 comments on commit c6528f4

Please sign in to comment.