{"record":{"id":"702cdc6ce89b59af","repo":"shwenzhang/AndResGuard","slug":"invalid-chunk-type-expected-0x-08x-got-0x-08x","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":"brut.androlib.AndrolibException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/ARSCDecoder.java","lineNumber":973,"sourceCode":"\n  private void writeConfigFlags() throws IOException, AndrolibException {\n    //总的有多大\n    int size = mIn.readInt();\n    if (size < 28) {\n      throw new AndrolibException(\"Config size < 28\");\n    }\n    mOut.writeInt(size);\n\n    mOut.writeBytes(mIn, size - 4);\n  }\n\n  private Header nextChunk() throws IOException {\n    return mHeader = Header.read(mIn);\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 Header writeNextChunk(int diffSize) throws IOException, AndrolibException {\n    mHeader = Header.readAndWriteHeader(mIn, mOut, diffSize);\n    return mHeader;\n  }\n\n  private Header writeNextChunkCheck(int expectedType, int diffSize) throws IOException, AndrolibException {\n    mHeader = Header.readAndWriteHeader(mIn, mOut, diffSize);","sourceCodeStart":955,"sourceCodeEnd":991,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/ARSCDecoder.java#L955-L991","documentation":"ARSCDecoder.checkChunkType verifies that the chunk header just read from resources.arsc has the expected chunk type constant (e.g. table, package, type spec). A mismatch means the arsc stream structure differs from what the decoder expects — either the file is corrupt, uses an unknown format version, or a previous chunk was parsed with the wrong length so the reader is now mid-stream.","triggerScenarios":"nextChunk() reads a header whose type field differs from expectedType during decode of the table, package, type-spec or config stages — triggered by corrupted arsc files, arsc with unsupported chunk types, or misaligned reads after an earlier malformed chunk.","commonSituations":"APKs processed by other tools that restructure resources.arsc, APKs built with very new aapt2 chunk types older AndResGuard doesn't know, or partially downloaded/corrupted APKs.","solutions":["Upgrade AndResGuard to support newer arsc chunk formats","Rebuild the APK with the standard Android build tools (aapt/aapt2)","Validate the input APK with aapt dump resources; re-obtain a clean copy if corrupt","Check that no other resource-processing tool ran before AndResGuard"],"exampleFix":"// before: AndResGuard 1.2.x on an APK built with new AGP/aapt2\n// after: bump the gradle dependency\nclasspath('com.tencent.mm:AndResGuard-gradle-plugin:1.2.21')","handlingStrategy":"try-catch","validationCode":"// pre-flight: dump the arsc chunk structure with aapt before processing\n// aapt dump resources app.apk > /dev/null || fail \"invalid resources.arsc\"","typeGuard":null,"tryCatchPattern":"try {\n  decodeArsc(arscStream);\n} catch (AndrolibException e) {\n  if (e.getMessage().startsWith(\"Invalid chunk type\")) {\n    // usually a format/tooling mismatch — upgrade tooling or rebuild, not a retry\n    throw new IllegalStateException(\"Unsupported or corrupt arsc chunk layout; rebuild with official aapt2\", e);\n  }\n  throw e;\n}","preventionTips":["Use a current Android SDK/AGP and current AndResGuard together","Verify APK integrity with aapt dump before processing","Avoid tools that reorder or rewrite arsc chunks upstream","Treat this as non-retryable: rebuild the input instead"],"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"}