{"record":{"id":"74666f248693e6ea","repo":"shwenzhang/AndResGuard","slug":"writespecnamestringblock-styleoffsetcount-0-styleoffsetcount","errorCode":null,"errorMessage":"writeSpecNameStringBlock styleOffsetCount != 0  styleOffsetCount %d","messagePattern":"writeSpecNameStringBlock styleOffsetCount != 0  styleOffsetCount (.+?)","errorType":"exception","errorClass":"AndrolibException","httpStatus":null,"severity":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/StringBlock.java","lineNumber":115,"sourceCode":"      int size = (chunkSize - stylesOffset);\n      if ((size % 4) != 0) {\n        throw new IOException(\"Style data size is not multiple of 4 (\" + size + \").\");\n      }\n      block.m_styles = reader.readIntArray(size / 4);\n    }\n    return block;\n  }\n\n  public static int writeSpecNameStringBlock(\n          ExtDataInput reader, ExtDataOutput out, Map<String, Set<String>> specNames, Map<String, Integer> curSpecNameToPos)\n      throws IOException, AndrolibException {\n    int type = reader.readInt();\n    int chunkSize = reader.readInt();\n    int stringCount = reader.readInt();\n    int styleOffsetCount = reader.readInt();\n\n    if (styleOffsetCount != 0) {\n      throw new AndrolibException(String.format(\"writeSpecNameStringBlock styleOffsetCount != 0  styleOffsetCount %d\",\n          styleOffsetCount\n      ));\n    }\n\n    int flags = reader.readInt();\n    boolean isUTF8 = (flags & UTF8_FLAG) != 0;\n    int stringsOffset = reader.readInt();\n    int stylesOffset = reader.readInt();\n    reader.readIntArray(stringCount);\n    int size = ((stylesOffset == 0) ? chunkSize : stylesOffset) - stringsOffset;\n\n    if ((size % 4) != 0) {\n      throw new IOException(\"String data size is not multiple of 4 (\" + size + \").\");\n    }\n    byte[] temp_strings = new byte[size];\n    reader.readFully(temp_strings);\n    int totalSize = 0;\n    out.writeCheckInt(type, CHUNK_STRINGPOOL_TYPE);","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/StringBlock.java#L97-L133","documentation":"writeSpecNameStringBlock re-reads the resource-table string pool while writing out a stripped spec-name block, and it only supports pools with no style spans. If styleOffsetCount (the style-offset array length in the chunk header) is non-zero, the writer cannot represent the styles and throws AndrolibException.","triggerScenarios":"Calling writeSpecNameStringBlock on a resources.arsc string pool whose header declares styleOffsetCount != 0 (the chunk contains styled strings/span info).","commonSituations":"Running AndResGuard over APKs that contain styled strings in the resource table (HTML-like <b>/<i> spans in resource strings), typically from apps with rich text resources.","solutions":["Remove or simplify styled (spanned) strings from resource tables so the string pool has no styles.","Use a newer AndResGuard version that may handle style sections, or patch StringBlock to copy the styles section verbatim.","As a workaround, pre-process the arsc with androidwide tooling (aapt2) to strip spans before obfuscation.","If the styled strings are only in resources.arsc (not needed at runtime), rebuild resources without formatting spans."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Inspect the string pool header before writing\nint styleOffsetCount = readIntAt(chunkStart + 20);\nif (styleOffsetCount != 0) {\n  // skip the spec-name fast path or strip styles first\n}","typeGuard":null,"tryCatchPattern":"try { block.writeSpecNameStringBlock(...); } catch (AndrolibException e) { if (e.getMessage().contains(\"styleOffsetCount != 0\")) { /* fall back to full (non-stripped) write path */ } else throw e; }","preventionTips":["Avoid styled/spanned strings in resource tables when using AndResGuard.","Run resource shrinking so styled strings are minimized before this stage.","Test obfuscation on a copy of the APK before release builds.","Keep AndResGuard updated for style-section handling improvements."],"tags":["android","resources-arsc","styled-strings","unsupported-input"],"backgroundTag":"unsupported-operation","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"}