{"record":{"id":"7e62baa707be64a7","repo":"HelloZeroNet/ZeroNet","slug":"bad-file-location","errorCode":null,"errorMessage":"Bad file location","messagePattern":"Bad file location","errorType":"exception","errorClass":"RequestError","httpStatus":null,"severity":"error","filePath":"src/File/FileRequest.py","lineNumber":241,"sourceCode":"            with file_obj as file:\n                file.seek(params[\"location\"])\n                read_bytes = params.get(\"read_bytes\", FILE_BUFF)\n                file_size = os.fstat(file.fileno()).st_size\n\n                if file_size > read_bytes:  # Check if file is readable at current position (for big files)\n                    if not self.isReadable(site, params[\"inner_path\"], file, params[\"location\"]):\n                        raise RequestError(\"File not readable at position: %s\" % params[\"location\"])\n                else:\n                    if params.get(\"file_size\") and params[\"file_size\"] != file_size:\n                        self.connection.badAction(2)\n                        raise RequestError(\"File size does not match: %sB != %sB\" % (params[\"file_size\"], file_size))\n\n                if not streaming:\n                    file.read_bytes = read_bytes\n\n                if params[\"location\"] > file_size:\n                    self.connection.badAction(5)\n                    raise RequestError(\"Bad file location\")\n\n                if streaming:\n                    back = {\n                        \"size\": file_size,\n                        \"location\": min(file.tell() + read_bytes, file_size),\n                        \"stream_bytes\": min(read_bytes, file_size - params[\"location\"])\n                    }\n                    self.response(back)\n                    self.sendRawfile(file, read_bytes=read_bytes)\n                else:\n                    back = {\n                        \"body\": file,\n                        \"size\": file_size,\n                        \"location\": min(file.tell() + file.read_bytes, file_size)\n                    }\n                    self.response(back, streaming=True)\n\n                bytes_sent = min(read_bytes, file_size - params[\"location\"])  # Number of bytes we going to send","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/HelloZeroNet/ZeroNet/blob/454c0b2e7e000fda7000cba49027541fbf327b96/src/File/FileRequest.py#L223-L259","documentation":"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.","triggerScenarios":"Thrown at src/File/FileRequest.py:241 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Client should restart the file request from location 0 or a known-good offset","Clamp/validate params['location'] against file size before attempting the read","Catch RequestError in actionGetFile/actionStreamFile and respond with an error object"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"454c0b2e7e000fda7000cba49027541fbf327b96","analyzedAt":"2026-09-02T19:46:57.278Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}