{"record":{"id":"89441e9f3d11357f","repo":"iBotPeaches/Apktool","slug":"repeated-type-spec-pkgid-0x-02x-typeid-0x-02x-t","errorCode":null,"errorMessage":"Repeated type spec: pkgId=0x%02x, typeId=0x%02x, typeName=%s","messagePattern":"Repeated type spec: pkgId=0x%02x, typeId=0x%02x, typeName=(.+?)","errorType":"exception","errorClass":"AndrolibException","httpStatus":null,"severity":"error","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/table/ResPackage.java","lineNumber":91,"sourceCode":"    }\n\n    public boolean hasTypeSpec(int typeId) {\n        return mTypeSpecs.containsKey(typeId);\n    }\n\n    public ResTypeSpec getTypeSpec(int typeId) throws UndefinedResObjectException {\n        ResTypeSpec typeSpec = mTypeSpecs.get(typeId);\n        if (typeSpec == null) {\n            throw new UndefinedResObjectException(\n                String.format(\"type spec: pkgId=0x%02x, typeId=0x%02x\", getId(), typeId));\n        }\n        return typeSpec;\n    }\n\n    public ResTypeSpec addTypeSpec(int typeId, String typeName) throws AndrolibException {\n        ResTypeSpec typeSpec = mTypeSpecs.get(typeId);\n        if (typeSpec != null) {\n            throw new AndrolibException(\n                String.format(\"Repeated type spec: pkgId=0x%02x, typeId=0x%02x, typeName=%s\",\n                    getId(), typeId, typeName));\n        }\n\n        typeSpec = new ResTypeSpec(this, typeId, typeName);\n        mTypeSpecs.put(typeId, typeSpec);\n        return typeSpec;\n    }\n\n    public int getTypeSpecCount() {\n        return mTypeSpecs.size();\n    }\n\n    public Collection<ResTypeSpec> listTypeSpecs() {\n        return mTypeSpecs.values();\n    }\n\n    public boolean hasType(int typeId) {","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/table/ResPackage.java#L73-L109","documentation":"AndrolibException thrown by ResPackage.addTypeSpec(typeId, typeName) when a ResTypeSpec for that typeId already exists in the package. The resource table model requires each (package, typeId) to have exactly one type spec; a second RES_TABLE_TYPE_SPEC chunk for the same typeId — or a duplicate programmatic add — triggers this.","triggerScenarios":"A malformed or maliciously crafted resources.arsc containing two type-spec chunks with the same typeId; parser re-reading the same package chunk; programmatic table construction calling addTypeSpec twice for one typeId.","commonSituations":"APKs processed by resource obfuscators/shrinkers that merge arsc data incorrectly; hand-edited or binary-patched resource tables; duplicated library resources after bad merging by third-party tools.","solutions":["When building a table, check hasTypeSpec(typeId) first and reuse the existing spec instead of adding again.","For malformed APKs, verify with aapt2 dump or a reference parser; if the file truly has duplicate chunks, it is corrupt — re-obtain it.","Decode with apktool's keep-broken-resources option only as a last resort to triage, then rebuild the arsc."],"exampleFix":"// before\nResTypeSpec spec = pkg.addTypeSpec(typeId, name); // throws on second call\n\n// after\nResTypeSpec spec = pkg.hasTypeSpec(typeId) ? pkg.getTypeSpec(typeId) : pkg.addTypeSpec(typeId, name);","handlingStrategy":"validation","validationCode":"if (pkg.hasTypeSpec(typeId)) {\n    ResTypeSpec spec = pkg.getTypeSpec(typeId); // reuse existing\n} else {\n    ResTypeSpec spec = pkg.addTypeSpec(typeId, typeName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    pkg.addTypeSpec(typeId, typeName);\n} catch (AndrolibException ex) {\n    // duplicate type-spec chunk in arsc -> corrupt file; report and stop parsing this package\n}","preventionTips":["Idempotent adds: check hasTypeSpec before addTypeSpec","Validate arsc with aapt2 dump resources when duplicates appear","Treat duplicate chunks as tampering/corruption, not as mergeable data"],"tags":["android","apktool","resource-table","duplicate","corruption"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}