{"record":{"id":"4179b6524b92d5d3","repo":"apache/hadoop","slug":"invalid-seek-offset-position-value-d-must-be","errorCode":null,"errorMessage":"Invalid seek offset: position value (%d) must be >= 0 for '%s'","messagePattern":"Invalid seek offset: position value \\((.+?)\\) must be >= 0 for '(.+?)'","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleCloudStorageClientReadChannel.java","lineNumber":589,"sourceCode":"  }\n\n  private IOException convertError(Exception error) {\n    String msg = String.format(\"Error reading '%s'\", resourceId);\n    switch (ErrorTypeExtractor.getErrorType(error)) {\n    case NOT_FOUND:\n      return createFileNotFoundException(\n          resourceId.getBucketName(), resourceId.getObjectName(), new IOException(msg, error));\n    case OUT_OF_RANGE:\n      return (IOException) new EOFException(msg).initCause(error);\n    default:\n      return new IOException(msg, error);\n    }\n  }\n\n  /** Validates that the given position is valid for this channel. */\n  private void validatePosition(long position) throws IOException {\n    if (position < 0) {\n      throw new EOFException(\n          String.format(\n              \"Invalid seek offset: position value (%d) must be >= 0 for '%s'\",\n              position, resourceId));\n    }\n\n    if (objectSize >= 0 && position >= objectSize) {\n      throw new EOFException(\n          String.format(\n              \"Invalid seek offset: position value (%d) must be between 0 and %d for '%s'\",\n              position, objectSize, resourceId));\n    }\n  }\n\n  /** Throws if this channel is not currently open. */\n  private void throwIfNotOpen() throws IOException {\n    if (!isOpen()) {\n      throw new ClosedChannelException();\n    }","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-gcp/src/main/java/org/apache/hadoop/fs/gs/GoogleCloudStorageClientReadChannel.java#L571-L607","documentation":"validatePosition throws EOFException when the requested seek position is negative. Any channel position must be >= 0; the check runs before the objectSize range check. Note the exception type is EOFException rather than IllegalArgumentException — chosen so Hadoop-side seek/position callers treat it as a read-position failure.","triggerScenarios":"Calling position(negative) on the client read channel — offsets produced by underflowing arithmetic such as pos - bytesRead going below zero, or record readers computing a previous-marker incorrectly.","commonSituations":"Off-by-one/underflow bugs in split-offset math in custom InputFormats; position bookkeeping that subtracts more than the current position; ported code assuming clamping semantics.","solutions":["Validate/clamp offsets to >= 0 before calling position/seek.","Fix the underflow arithmetic (guard subtractions, use Math.max(0, candidate)).","Treat occurrence as a caller bug: add a precondition in your position-tracking code."],"exampleFix":"// before\nlong target = currentPos - overshoot; // can go negative\nch.position(target);\n\n// after\nlong target = Math.max(0, currentPos - overshoot);\nch.position(target);","handlingStrategy":"validation","validationCode":"long safeTarget = Math.max(0, computedOffset);\nif (safeTarget != computedOffset) LOG.warn(\"clamped negative offset {} -> 0\", computedOffset);\nch.position(safeTarget);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard every subtraction used for positions with Math.max(0, ...).","Unit-test offset math with boundary inputs (0-position reads, overshoot larger than position).","Treat negative-seek as a caller bug in logs — fix the arithmetic, don't clamp in production silently."],"tags":["gcs","seek","negative-offset","validation","read-channel"],"backgroundTag":"negative-seek-offset","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}