MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / CheckIntraStringDataItem

Method CheckIntraStringDataItem

Bcore/src/main/cpp/dex/dex_file_verifier.cc:1332–1416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1330}
1331
1332bool DexFileVerifier::CheckIntraStringDataItem() {
1333 DECODE_UNSIGNED_CHECKED_FROM(ptr_, size);
1334 const uint8_t* file_end = begin_ + size_;
1335
1336 for (uint32_t i = 0; i < size; i++) {
1337 CHECK_LT(i, size); // b/15014252 Prevents hitting the impossible case below
1338 if (UNLIKELY(ptr_ >= file_end)) {
1339 ErrorStringPrintf("String data would go beyond end-of-file");
1340 return false;
1341 }
1342
1343 uint8_t byte = *(ptr_++);
1344
1345 // Switch on the high 4 bits.
1346 switch (byte >> 4) {
1347 case 0x00:
1348 // Special case of bit pattern 0xxx.
1349 if (UNLIKELY(byte == 0)) {
1350 CHECK_LT(i, size); // b/15014252 Actually hit this impossible case with clang
1351 ErrorStringPrintf("String data shorter than indicated utf16_size %x", size);
1352 return false;
1353 }
1354 break;
1355 case 0x01:
1356 case 0x02:
1357 case 0x03:
1358 case 0x04:
1359 case 0x05:
1360 case 0x06:
1361 case 0x07:
1362 // No extra checks necessary for bit pattern 0xxx.
1363 break;
1364 case 0x08:
1365 case 0x09:
1366 case 0x0a:
1367 case 0x0b:
1368 case 0x0f:
1369 // Illegal bit patterns 10xx or 1111.
1370 // Note: 1111 is valid for normal UTF-8, but not here.
1371 ErrorStringPrintf("Illegal start byte %x in string data", byte);
1372 return false;
1373 case 0x0c:
1374 case 0x0d: {
1375 // Bit pattern 110x has an additional byte.
1376 uint8_t byte2 = *(ptr_++);
1377 if (UNLIKELY((byte2 & 0xc0) != 0x80)) {
1378 ErrorStringPrintf("Illegal continuation byte %x in string data", byte2);
1379 return false;
1380 }
1381 uint16_t value = ((byte & 0x1f) << 6) | (byte2 & 0x3f);
1382 if (UNLIKELY((value != 0) && (value < 0x80))) {
1383 ErrorStringPrintf("Illegal representation for value %x in string data", value);
1384 return false;
1385 }
1386 break;
1387 }
1388 case 0x0e: {
1389 // Bit pattern 1110 has 2 additional bytes.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected