{"record":{"id":"76121e469c2ca82a","repo":"apache/hadoop","slug":"unrecognized-fsimage-76121e","errorCode":null,"errorMessage":"Unrecognized FSImage","messagePattern":"Unrecognized FSImage","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java","lineNumber":290,"sourceCode":"  private final SimpleDateFormat isoDateFormat;\n  private SerialNumberManager.StringTable stringTable;\n\n  public static SimpleDateFormat createSimpleDateFormat() {\n    SimpleDateFormat format =\n      new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss.SSS\");\n    format.setTimeZone(TimeZone.getTimeZone(\"UTC\"));\n    return format;\n  }\n\n  public PBImageXmlWriter(Configuration conf, PrintStream out) {\n    this.conf = conf;\n    this.out = out;\n    this.isoDateFormat = createSimpleDateFormat();\n  }\n\n  public void visit(RandomAccessFile file) throws IOException {\n    if (!FSImageUtil.checkFileFormat(file)) {\n      throw new IOException(\"Unrecognized FSImage\");\n    }\n\n    FileSummary summary = FSImageUtil.loadSummary(file);\n    try (FileInputStream fin = new FileInputStream(file.getFD())) {\n      out.print(\"<?xml version=\\\"1.0\\\"?>\\n<fsimage>\");\n\n      out.print(\"<version>\");\n      o(\"layoutVersion\", summary.getLayoutVersion());\n      o(\"onDiskVersion\", summary.getOndiskVersion());\n      // Output the version of OIV (which is not necessarily the version of\n      // the fsimage file).  This could be helpful in the case where a bug\n      // in OIV leads to information loss in the XML-- we can quickly tell\n      // if a specific fsimage XML file is affected by this bug.\n      o(\"oivRevision\", VersionInfo.getRevision());\n      out.print(\"</version>\\n\");\n\n      ArrayList<FileSummary.Section> sections = Lists.newArrayList(summary\n          .getSectionsList());","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageXmlWriter.java#L272-L308","documentation":"Identical gate to the text writer's: PBImageXmlWriter.visit() (the `hdfs oiv -p XML` processor) checks the 'HDFSIMG1' magic and minimum file length before parsing. Failure means the input is not a protobuf fsimage — an edit log, the .md5 sidecar, a legacy pre-2.x image, a truncated download, or an unrelated file.","triggerScenarios":"Passing a non-fsimage file to `hdfs oiv -p XML -i <file>`: edits logs, fsimage.md5, legacy-format images, truncated or partially downloaded files.","commonSituations":"Shell glob picking the wrong file from the NameNode directory; interrupted transfers; legacy images run through the PB tool by mistake.","solutions":["Check the magic: `head -c 8 <file>` must print HDFSIMG1","Pass the explicit fsimage_<txid> path rather than a glob","Verify with the sibling fsimage.md5 and re-transfer if it mismatches","For pre-Hadoop-2 images use `hdfs oiv_legacy -p XML`"],"exampleFix":"# before\nhdfs oiv -p XML -i /tmp/maybe-image -o out.xml\n# IOException: Unrecognized FSImage\n\n# after\nhead -c 8 /tmp/maybe.xml >/dev/null; head -c 8 /dfs/name/current/fsimage_0000000000000123456  # HDFSIMG1\nhdfs oiv -p XML -i /dfs/name/current/fsimage_0000000000000123456 -o out.xml","handlingStrategy":"validation","validationCode":"// Same gate as the text writer: check magic before PBImageXmlWriter.visit()\ntry (RandomAccessFile f = new RandomAccessFile(path, \"r\")) {\n  byte[] magic = new byte[FSImageUtil.MAGIC_HEADER.length];\n  f.readFully(magic);\n  if (!Arrays.equals(magic, FSImageUtil.MAGIC_HEADER)) {\n    throw new IllegalArgumentException(path + \" is not a protobuf fsimage\");\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check `head -c 8` output for HDFSIMG1 before running -p XML","Do not feed edits logs, fsimage.md5, or legacy images to the PB tool","Keep pre-2.x analysis on `hdfs oiv_legacy`"],"tags":["hdfs","offline-image-viewer","fsimage","xml","file-format"],"backgroundTag":"invalid-file-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}