HelloZeroNet/ZeroNet · error · RequestError

Bad file location

Error message

Bad file location

What it means

Generic RequestError sentinel raised in handleGetFile when the requested params['location'] is not a valid readable offset in the served file (seek/read bounds check failed and no more specific error applied). The input at fault is an out-of-range or invalid location value from the peer's request.

Source

Thrown at src/File/FileRequest.py:241

            with file_obj as file:
                file.seek(params["location"])
                read_bytes = params.get("read_bytes", FILE_BUFF)
                file_size = os.fstat(file.fileno()).st_size

                if file_size > read_bytes:  # Check if file is readable at current position (for big files)
                    if not self.isReadable(site, params["inner_path"], file, params["location"]):
                        raise RequestError("File not readable at position: %s" % params["location"])
                else:
                    if params.get("file_size") and params["file_size"] != file_size:
                        self.connection.badAction(2)
                        raise RequestError("File size does not match: %sB != %sB" % (params["file_size"], file_size))

                if not streaming:
                    file.read_bytes = read_bytes

                if params["location"] > file_size:
                    self.connection.badAction(5)
                    raise RequestError("Bad file location")

                if streaming:
                    back = {
                        "size": file_size,
                        "location": min(file.tell() + read_bytes, file_size),
                        "stream_bytes": min(read_bytes, file_size - params["location"])
                    }
                    self.response(back)
                    self.sendRawfile(file, read_bytes=read_bytes)
                else:
                    back = {
                        "body": file,
                        "size": file_size,
                        "location": min(file.tell() + file.read_bytes, file_size)
                    }
                    self.response(back, streaming=True)

                bytes_sent = min(read_bytes, file_size - params["location"])  # Number of bytes we going to send

View on GitHub (pinned to 454c0b2e7e)

Solutions

  1. Client should restart the file request from location 0 or a known-good offset
  2. Clamp/validate params['location'] against file size before attempting the read
  3. Catch RequestError in actionGetFile/actionStreamFile and respond with an error object
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/File/FileRequest.py:241 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HelloZeroNet/ZeroNet@454c0b2e7e (2026-09-02). Data as JSON: /api/errors/7e62baa707be64a7. Report an issue: GitHub.