{"record":{"id":"e3846a554ba9301c","repo":"apache/hadoop","slug":"error-untarring-file-infile-tar-process-e","errorCode":null,"errorMessage":"Error untarring file \" + inFile + \". Tar process exited with exit code \" + exitcode + \" from command \" + untarCommand","messagePattern":"Error untarring file \" \\+ inFile \\+ \"\\. Tar process exited with exit code \" \\+ exitcode \\+ \" from command \" \\+ untarCommand","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":1080,"sourceCode":"          .append(\" | (\");\n    }\n    untarCommand.append(\"cd '\")\n        .append(FileUtil.makeSecureShellPath(untarDir))\n        .append(\"' && \")\n        .append(\"tar -xf \");\n\n    if (gzipped) {\n      untarCommand.append(\" -)\");\n    } else {\n      untarCommand.append(source);\n    }\n    LOG.debug(\"executing [{}]\", untarCommand);\n    String[] shellCmd = { \"bash\", \"-c\", untarCommand.toString() };\n    ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd);\n    shexec.execute();\n    int exitcode = shexec.getExitCode();\n    if (exitcode != 0) {\n      throw new IOException(\"Error untarring file \" + inFile +\n          \". Tar process exited with exit code \" + exitcode\n          + \" from command \" + untarCommand);\n    }\n  }\n\n  static void unTarUsingJava(File inFile, File untarDir,\n      boolean gzipped) throws IOException {\n    InputStream inputStream = null;\n    TarArchiveInputStream tis = null;\n    try {\n      if (gzipped) {\n        inputStream =\n            new GZIPInputStream(Files.newInputStream(inFile.toPath()));\n      } else {\n        inputStream = Files.newInputStream(inFile.toPath());\n      }\n\n      inputStream = new BufferedInputStream(inputStream);","sourceCodeStart":1062,"sourceCodeEnd":1098,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L1062-L1098","documentation":"unTarUsingTar builds a bash command ('bash','-c','tar -xf ... -)') and runs it via ShellCommandExecutor on non-Windows; a non-zero exit code throws IOException(\"Error untarring file <inFile>. Tar process exited with exit code <n> from command <cmd>\"). Unlike the runCommand variant, this message includes the exact tar command, which usually reveals the cause. Common exit codes: 1/2 corrupt or truncated archive, 127 tar not found, 126 permission problem on tar.","triggerScenarios":"unTar(File inFile, File untarDir) or unTar(stream,...) on Linux with a truncated .tar/.tgz; tar binary absent from PATH (exit 127); archive containing entries the system tar cannot create (unsupported link types, path too long); untarDir unwritable.","commonSituations":"Downloaded tarballs truncated by network or proxy; minimal Docker images without tar; archives created with GNU extensions failing on BusyBox tar; running as a user without write permission on the extraction dir.","solutions":["Run the printed command manually to see tar's own stderr — it names the exact failing entry or missing binary","Validate the archive (tar -tf / checksum) and re-download or regenerate it","Install/point to a full GNU tar, or catch this IOException and retry with the pure-Java path: FileUtil.unTarUsingJava(inFile, untarDir, gzipped) via a manual extraction routine","Confirm write permission on untarDir and disk space"],"exampleFix":"// before\nFileUtil.unTar(inFile, untarDir);\n// Error untarring file bundle.tgz. Tar process exited with exit code 2 from command ...\n\n// after: fall back to the Java implementation when native tar fails\ntry {\n  FileUtil.unTar(inFile, untarDir);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Tar process exited\")) {\n    try (InputStream in = Files.newInputStream(inFile.toPath())) {\n      FileUtil.unTar(in, untarDir, inFile.getName().endsWith(\"gz\"));\n    }\n  } else {\n    throw e;\n  }\n}","handlingStrategy":"fallback","validationCode":"try (InputStream probe = Files.newInputStream(inFile.toPath())) {\n  byte[] m = new byte[2];\n  if (probe.read(m) == 2 && (m[0] & 0xff) == 0x1f) {\n    // gzip magic: unTar(File,...) infers gzipped from name only — rename or use stream API\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileUtil.unTar(inFile, untarDir);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Tar process exited\")) {\n    // native tar failed; retry with the pure-Java extractor\n    try (InputStream in = Files.newInputStream(inFile.toPath())) {\n      FileUtil.unTar(in, untarDir, inFile.getName().endsWith(\"gz\"));\n    }\n  } else throw e;\n}","preventionTips":["Run the failing printed tar command manually once — its stderr names the bad entry or missing binary","Keep GNU tar available on extraction nodes or plan the Java fallback","Verify archive integrity before deploying to nodes"],"tags":["untar","shell-command","exit-code","corrupt-archive","archive-extraction"],"backgroundTag":"archive-extraction-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}