Download tasks/codeql_python_benchmark51_v2/pyvul-8e39d07d2ff863a3f19e/patch.diff from Benchanything/checkerbench: direct link, hf CLI and curl.
- Browser
- Download file 3.33 kB
-
https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-8e39d07d2ff863a3f19e/patch.diff
- Command line
-
hf download hf://datasets/Benchanything/checkerbench/tasks/codeql_python_benchmark51_v2/pyvul-8e39d07d2ff863a3f19e/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-8e39d07d2ff863a3f19e/patch.diff
3.33 kB
| diff --git a/xhu.py b/xhu.py | |
| index a28c5a8..b999957 100644 | |
| --- a/xhu.py | |
| +++ b/xhu.py | |
| import pathlib | |
| import typing | |
| import flask | |
| +import werkzeug.exceptions | |
| app = flask.Flask("xmpp-http-upload") | |
| app.config.from_envvar("XMPP_HTTP_UPLOAD_CONFIG") | |
| if app.config['ENABLE_CORS']: | |
| CORS(app) | |
| -def sanitized_join(path: str, root: pathlib.Path) -> pathlib.Path: | |
| - result = (root / path).absolute() | |
| - if not str(result).startswith(str(root) + "/"): | |
| - raise ValueError("resulting path is outside root") | |
| - return result | |
| - | |
| - | |
| -def get_paths(base_path: pathlib.Path): | |
| - data_file = pathlib.Path(str(base_path) + ".data") | |
| - metadata_file = pathlib.Path(str(base_path) + ".meta") | |
| +def get_paths(root: str, sub_path: str) \ | |
| + -> typing.Tuple[pathlib.Path, pathlib.Path]: | |
| + base_path = flask.safe_join(root, sub_path) | |
| + data_file = pathlib.Path(base_path + ".data") | |
| + metadata_file = pathlib.Path(base_path + ".meta") | |
| return data_file, metadata_file | |
| def load_metadata(metadata_file): | |
| return json.load(f) | |
| -def get_info(path: str, root: pathlib.Path) -> typing.Tuple[ | |
| +def get_info(path: str) -> typing.Tuple[ | |
| pathlib.Path, | |
| dict]: | |
| - dest_path = sanitized_join( | |
| - path, | |
| - pathlib.Path(app.config["DATA_ROOT"]), | |
| - ) | |
| - | |
| - data_file, metadata_file = get_paths(dest_path) | |
| + data_file, metadata_file = get_paths(app.config["DATA_ROOT"], path) | |
| return data_file, load_metadata(metadata_file) | |
| def stream_file(src, dest, nbytes): | |
| @app.route("/<path:path>", methods=["PUT"]) | |
| def put_file(path): | |
| try: | |
| - dest_path = sanitized_join( | |
| - path, | |
| - pathlib.Path(app.config["DATA_ROOT"]), | |
| - ) | |
| - except ValueError: | |
| + data_file, metadata_file = get_paths(app.config["DATA_ROOT"], path) | |
| + except werkzeug.exceptions.NotFound: | |
| return flask.Response( | |
| "Not Found", | |
| 404, | |
| def put_file(path): | |
| "application/octet-stream", | |
| ) | |
| - dest_path.parent.mkdir(parents=True, exist_ok=True, mode=0o770) | |
| - data_file, metadata_file = get_paths(dest_path) | |
| + data_file.parent.mkdir(parents=True, exist_ok=True, mode=0o770) | |
| try: | |
| with write_file(data_file) as fout: | |
| def generate_headers(response_headers, metadata_headers): | |
| @app.route("/<path:path>", methods=["HEAD"]) | |
| def head_file(path): | |
| try: | |
| - data_file, metadata = get_info( | |
| - path, | |
| - pathlib.Path(app.config["DATA_ROOT"]) | |
| - ) | |
| + data_file, metadata = get_info(path) | |
| stat = data_file.stat() | |
| - except (OSError, ValueError): | |
| + except (OSError, werkzeug.exceptions.NotFound): | |
| return flask.Response( | |
| "Not Found", | |
| 404, | |
| def head_file(path): | |
| @app.route("/<path:path>", methods=["GET"]) | |
| def get_file(path): | |
| try: | |
| - data_file, metadata = get_info( | |
| - path, | |
| - pathlib.Path(app.config["DATA_ROOT"]) | |
| - ) | |
| - except (OSError, ValueError): | |
| + data_file, metadata = get_info(path) | |
| + except (OSError, werkzeug.exceptions.NotFound): | |
| return flask.Response( | |
| "Not Found", | |
| 404, | |