{"record":{"id":"9a5d2530f53c0f5e","repo":"apache/iceberg","slug":"incorrect-length-provided-for-file-location-giv","errorCode":null,"errorMessage":"Incorrect length provided for file <location>, given a length of <length> and did not reach the end of stream","messagePattern":"Incorrect length provided for file <location>, given a length of <length> and did not reach the end of stream","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/io/EagerInputFile.java","lineNumber":80,"sourceCode":"\n  @Override\n  public String location() {\n    return delegate.location();\n  }\n\n  @Override\n  public boolean exists() {\n    return delegate.exists();\n  }\n\n  @Override\n  public SeekableInputStream newStream() {\n    byte[] bytes = new byte[(int) length];\n    try (SeekableInputStream src = delegate.newStream()) {\n      IOUtil.readFully(src, bytes, 0, bytes.length);\n      // reads from the already open stream; no additional request\n      if (src.read() != -1) {\n        throw new IOException(\n            \"Incorrect length provided for file \"\n                + delegate.location()\n                + \", given a length of \"\n                + length\n                + \" and did not reach the end of stream\");\n      }\n    } catch (IOException e) {\n      throw new RuntimeIOException(e, \"Failed to fetch file: %s\", delegate.location());\n    }\n    return new EagerInputStream(bytes);\n  }\n\n  /** An {@link EagerInputFile} that preserves the delegate's Hadoop configuration. */\n  private static class EagerInputFileConfigurable extends EagerInputFile\n      implements HadoopConfigurable {\n\n    private final HadoopConfigurable delegate;\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/io/EagerInputFile.java#L62-L98","documentation":"EagerInputFile.newStream reads the whole file into memory using the length supplied at construction. If after reading `length` bytes the stream is not yet at EOF, the actual file is longer than the declared length, so the eager read would silently truncate. It throws IOException (later wrapped as RuntimeIOException) to prevent reading partial data.","triggerScenarios":"Creating EagerInputFile (e.g. InputFile.local(?) or fromCache with an explicit length) where the length parameter is smaller than the real file size, then calling newStream().","commonSituations":"Passing a stale/incorrect length taken from old metadata or manifest stats; hardcoding a length; a file that grew after the length was captured; manifest entries with wrong file size.","solutions":["Construct the eager file with the actual current file size (file.length() / accurate manifest length).","Drop the explicit length and let the InputFile determine it from storage.","Recompute table/manifest metadata if file sizes are stale.","Verify the file was not modified after the length was captured (Iceberg files must be immutable)."],"exampleFix":"// before\nInputFile f = InputFile.local(path, 1024); // hardcoded length\n// after\nlong len = Files.size(Paths.get(path));\nInputFile f = InputFile.local(path, len);","handlingStrategy":"validation","validationCode":"long real = file.getLength();\nPreconditions.checkArgument(declaredLength == real,\n    \"Declared length %s != actual %s\", declaredLength, real);","typeGuard":null,"tryCatchPattern":"try {\n  return eagerFile.newStream();\n} catch (RuntimeIOException e) {\n  if (e.getMessage().contains(\"Incorrect length\")) {\n    return io.newInputFile(location).newStream(); // lazy, derives length itself\n  }\n  throw e;\n}","preventionTips":["Never hardcode file lengths; read them from file.length() or manifests","Remember Iceberg files are immutable — a growing file signals a bug","Validate manifest-reported file sizes against storage when debugging","Avoid wrapping files in EagerInputFile with lengths from stale metadata"],"tags":["length-mismatch","memory","io"],"backgroundTag":"invalid-argument-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}