{"record":{"id":"94a93fbd7c097b6d","repo":"shwenzhang/AndResGuard","slug":"could-not-decode-arsc-file-rawarscdecoder","errorCode":null,"errorMessage":"Could not decode arsc file","messagePattern":"Could not decode arsc file","errorType":"exception","errorClass":"brut.androlib.AndrolibException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/RawARSCDecoder.java","lineNumber":75,"sourceCode":"  private ResType mType;\n  private int mTypeIdOffset = 0;\n  private int mCurTypeID = -1;\n  private ResPackage[] mPkgs;\n  private int mResId;\n\n  private RawARSCDecoder(InputStream arscStream) throws AndrolibException, IOException {\n    arscStream = mCountIn = new CountingInputStream(arscStream);\n    mIn = new ExtDataInput(new LEDataInputStream(arscStream));\n    mExistTypeNames = new HashMap<>();\n  }\n\n  public static ResPackage[] decode(InputStream arscStream) throws AndrolibException {\n    try {\n      RawARSCDecoder decoder = new RawARSCDecoder(arscStream);\n      System.out.printf(\"parse to get the exist names in the resouces.arsc first\\n\");\n      return decoder.readTable();\n    } catch (IOException ex) {\n      throw new AndrolibException(\"Could not decode arsc file\", ex);\n    }\n  }\n\n  public static Set<String> getExistTypeSpecNameStrings(int type) {\n    return mExistTypeNames.get(type);\n  }\n\n  private ResPackage[] readTable() throws IOException, AndrolibException {\n    nextChunkCheckType(Header.TYPE_TABLE);\n    int packageCount = mIn.readInt();\n    StringBlock.read(mIn);\n    ResPackage[] packages = new ResPackage[packageCount];\n    nextChunk();\n    for (int i = 0; i < packageCount; i++) {\n      packages[i] = readTablePackage();\n    }\n    return packages;\n  }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/RawARSCDecoder.java#L57-L93","documentation":"RawARSCDecoder.decode performs a raw first pass over resources.arsc to collect existing resource names. Any IOException while streaming the arsc (truncation, premature EOF, unreadable bytes) is wrapped into AndrolibException(\"Could not decode arsc file\") with the original cause attached. It signals the arsc could not be parsed at the byte level.","triggerScenarios":"decoder.readTable() throws IOException — the arscStream ends prematurely (truncated file), the underlying zip entry cannot be read, or the byte stream is corrupted.","commonSituations":"Corrupted or partially downloaded APKs, APKs whose resources.arsc entry was damaged by another packing tool, filesystem/IO errors while reading the APK, or an encrypted/modified arsc entry.","solutions":["Verify the APK: unzip -t app.apk and aapt dump badging; re-obtain a clean build if corrupt","Rebuild the APK with standard Android build tooling and retry","Check disk space and file permissions on the build machine","Update AndResGuard; if the cause is a legit format change, the wrapped cause exception will say which read failed"],"exampleFix":"// before: feeding a corrupted apk\nAndResGuard.process(brokenApk)\n// after: validate first\n// unzip -t app.apk && aapt dump badging app.apk\nAndResGuard.process(verifiedApk)","handlingStrategy":"try-catch","validationCode":"// verify apk/arsc integrity before decoding\nProcess p = new ProcessBuilder(\"aapt\", \"dump\", \"badging\", apkPath).start();\nif (p.waitFor() != 0) throw new IllegalArgumentException(\"APK is invalid: \" + apkPath);","typeGuard":null,"tryCatchPattern":"try {\n  RawARSCDecoder.decode(arscStream);\n} catch (AndrolibException e) {\n  if (\"Could not decode arsc file\".equals(e.getMessage())) {\n    logger.error(\"arsc unreadable (cause: \" + e.getCause() + \"); verify the apk is not corrupted\");\n    throw new BuildException(\"Corrupt resources.arsc — obtain a clean build\", e);\n  }\n  throw e;\n}","preventionTips":["Checksum APKs after download/transfer before processing","Check disk space and permissions on build machines","Verify with unzip -t / aapt dump before obfuscation","Inspect e.getCause() to pinpoint the failing read"],"tags":["android","arsc","io","corrupt-input"],"backgroundTag":"file-read-failed","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"}