{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "72abb57b", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/andrestorhaug/Downloads/hf/ok/VulFixMiner/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n", "W1115 22:41:10.820000 31086 torch/distributed/elastic/multiprocessing/redirects.py:35] NOTE: Redirects are currently not supported in MacOs.\n", "Loading weights: 100%|██████████| 203/203 [00:00<00:00, 13171.68it/s]\n" ] } ], "source": [ "from transformers import pipeline\n", "\n", "classifier = pipeline(\n", " \"text-classification\",\n", " model=\".\", # Local repository; replace with your Hub model ID after upload.\n", " trust_remote_code=True,\n", " device=\"cpu\", # Also supports \"cuda\" or \"mps\".\n", " file_batch_size=32,\n", ")\n" ] }, { "cell_type": "code", "execution_count": 29, "id": "6473f3d8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Security-patch probability: 3.8624143599008676e-06\n" ] } ], "source": [ "\n", "diff = \"\"\"commit f71d502fcb5c77fa80ad8e305de5fdf13e2bad7f\n", "Author: Robert Brewer \n", "Date: Sat Oct 27 17:15:58 2007 +0000\n", "\n", " Trunk fix for #744 (Malicious cookies may allow access to files outside the session directory).\n", "\n", "diff --git a/cherrypy/lib/sessions.py b/cherrypy/lib/sessions.py\n", "index 8b1c3760..810b8c7e 100644\n", "--- a/cherrypy/lib/sessions.py\n", "+++ b/cherrypy/lib/sessions.py\n", "@@ -282,7 +282,10 @@ class FileSession(Session):\n", " setup = classmethod(setup)\n", " \n", " def _get_file_path(self):\n", "- return os.path.join(self.storage_path, self.SESSION_PREFIX + self.id)\n", "+ f = os.path.join(self.storage_path, self.SESSION_PREFIX + self.id)\n", "+ if not os.path.normpath(f).startswith(self.storage_path):\n", "+ raise cherrypy.HTTPError(400, \"Invalid session id in cookie.\")\n", "+ return f\n", " \n", " def _load(self, path=None):\n", " if path is None:\n", "\"\"\"\n", "\n", "security_probability = classifier(diff) # One float between 0 and 1.\n", "print(\"Security-patch probability:\", security_probability)\n", "\n", "# Lists contain independent commits, not files from the same commit.\n", "batch_scores = classifier([diff, diff]) # One float per commit, in input order." ] }, { "cell_type": "code", "execution_count": 30, "id": "42fd8b8b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[3.8624143599008676e-06, 3.8624143599008676e-06]" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "batch_scores" ] } ], "metadata": { "kernelspec": { "display_name": ".venv (3.13.11)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.11" } }, "nbformat": 4, "nbformat_minor": 5 }