{"record":{"id":"fb5d348e85b54e56","repo":"apache/hadoop","slug":"attempting-to-read-from-negative-offset","errorCode":null,"errorMessage":"attempting to read from negative offset","messagePattern":"attempting to read from negative offset","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java","lineNumber":652,"sourceCode":"   * Uses the Content-Range header to determine the total file size, which is necessary\n   * for handling partial reads correctly.\n   *\n   * @param op the ABFS HTTP operation containing the response headers\n   * @return the content length of the file\n   */\n  private long extractContentLength(AbfsHttpOperation op) {\n    // We need to use content range header instead of content length to take care of partial reads\n    String contentRange = op.getResponseHeader(HttpHeaderConfigurations.CONTENT_RANGE);\n    contentLength = 0;\n    if (!StringUtils.isEmpty(contentRange)) {\n      contentLength = Long.parseLong(contentRange.split(AbfsHttpConstants.FORWARD_SLASH)[1]);\n    }\n    return contentLength;\n  }\n\n  int readRemote(long position, byte[] b, int offset, int length, TracingContext tracingContext) throws IOException {\n    if (position < 0) {\n      throw new IllegalArgumentException(\"attempting to read from negative offset\");\n    }\n    if (!(shouldRestrictGpsOnOpenFile() && isFirstRead()) && position >= contentLength) {\n      return -1;  // Hadoop prefers -1 to EOFException\n    }\n    if (b == null) {\n      throw new IllegalArgumentException(\"null byte array passed in to read() method\");\n    }\n    if (offset >= b.length) {\n      throw new IllegalArgumentException(\"offset greater than length of array\");\n    }\n    if (length < 0) {\n      throw new IllegalArgumentException(\"requested read length is less than zero\");\n    }\n    if (length > (b.length - offset)) {\n      throw new IllegalArgumentException(\"requested read length is more than will fit after requested offset in buffer\");\n    }\n    final AbfsRestOperation op;\n    AbfsPerfTracker tracker = client.getAbfsPerfTracker();","sourceCodeStart":634,"sourceCodeEnd":670,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java#L634-L670","documentation":"Error \"attempting to read from negative offset\" thrown in apache/hadoop.","triggerScenarios":"A positioned read is requested with a negative buffer offset.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-negative offset to read(position, buffer, offset, length).","Validate offsets computed by application code before issuing positioned reads."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}