{"record":{"id":"307915d51b0505ab","repo":"shwenzhang/AndResGuard","slug":"invalid-chunk-type-expected-0x-08x-got-0x-08x-rawarscdecoder","errorCode":null,"errorMessage":"Invalid chunk type: expected=0x%08x, got=0x%08x","messagePattern":"Invalid chunk type: expected=0x%08x, got=0x%08x","errorType":"exception","errorClass":"AndrolibException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/RawARSCDecoder.java","lineNumber":354,"sourceCode":"    while (length-- != 0) {\n      short ch = mIn.readByte();\n      if (ch == 0) {\n        break;\n      }\n      string.append((char) ch);\n    }\n    mIn.skipBytes(length);\n\n    return string.toString();\n  }\n\n  private Header nextChunk() throws IOException {\n    return mHeader = Header.read(mIn, mCountIn);\n  }\n\n  private void checkChunkType(int expectedType) throws AndrolibException {\n    if (mHeader.type != expectedType) {\n      throw new AndrolibException(String.format(\"Invalid chunk type: expected=0x%08x, got=0x%08x\",\n          expectedType,\n          mHeader.type\n      ));\n    }\n  }\n\n  private void nextChunkCheckType(int expectedType) throws IOException, AndrolibException {\n    nextChunk();\n    checkChunkType(expectedType);\n  }\n\n  private void putTypeSpecNameStrings(int type, String name) {\n    Set<String> names = mExistTypeNames.get(type);\n    if (names == null) {\n      names = new HashSet<>();\n    }\n    names.add(name);\n    mExistTypeNames.put(type, names);","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/RawARSCDecoder.java#L336-L372","documentation":"RawARSCDecoder.checkChunkType validates that the chunk header read by nextChunk() matches the expected chunk type constant while walking the table, package, library, type-spec and config sections of resources.arsc. A mismatch indicates the arsc's structural layout differs from the expected format — corruption, an unsupported format version, or a misaligned read.","triggerScenarios":"Called from readTablePackage, readLibraryType, readSingleTableTypeSpec, readConfig or nextChunkCheckType when mHeader.type != expectedType — e.g. an unknown/missing library chunk, a package chunk where a type-spec was expected, or garbage after a truncated section.","commonSituations":"APKs with shared-library chunks (library type) handled by older AndResGuard, arsc produced by new aapt2 versions, repacked/corrupted APKs, or non-standard resource tools.","solutions":["Upgrade AndResGuard to a version supporting the arsc features in your APK (e.g. shared library chunks)","Rebuild the APK with the official Android build tools","Verify the input APK integrity (aapt dump resources) and re-obtain a clean copy","Disable other resource-processing plugins that may rewrite resources.arsc before AndResGuard runs"],"exampleFix":"// before: old plugin choking on aapt2 library chunks\nclasspath('com.tencent.mm:AndResGuard-gradle-plugin:1.1.x')\n// after\nclasspath('com.tencent.mm:AndResGuard-gradle-plugin:1.2.21')","handlingStrategy":"try-catch","validationCode":"// pre-check: ensure aapt can fully walk the arsc\n// aapt dump resources app.apk > /dev/null || exit 1","typeGuard":null,"tryCatchPattern":"try {\n  RawARSCDecoder.decode(arscStream);\n} catch (AndrolibException e) {\n  if (e.getMessage().startsWith(\"Invalid chunk type\")) {\n    logger.warn(\"Unexpected arsc chunk — upgrading AndResGuard or rebuilding the apk\");\n    fallbackToUnobfuscatedBuild();\n  } else throw e;\n}","preventionTips":["Match AndResGuard version to your AGP/aapt2 version","Verify APKs with aapt dump before processing","Disable other plugins that rewrite resources.arsc upstream","Do not retry on the same corrupt input; rebuild it"],"tags":["android","arsc","chunk-parsing","format-mismatch"],"backgroundTag":"unexpected-response-shape","analyzedSha":"e4df245d82f27d9a2d0dd108260a3510cbaba849","analyzedAt":"2026-09-12T17:49:07.798Z","contentChangedAt":"2026-09-12T17:49:07.798Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}