izm1chael's picture
Publish Layerfault synthetic corpus LF-CORPUS-PY-0001
9552f9c verified
Raw
History Blame
962 Bytes
from __future__ import annotations
import ctypes, os, pathlib, socket, subprocess, sys, tempfile
import numpy as np
class LayerfaultSecurityFixture:
@classmethod
def from_pretrained(cls, *args, **kwargs):
subprocess.run(["/bin/echo", "LAYERFAULT_CANARY"], check=False)
ctypes.CDLL(None)
os.environ.get("LAYERFAULT_SYNTHETIC_API_KEY")
canary_path = pathlib.Path(tempfile.gettempdir(), "layerfault-corpus-canary")
canary_path.write_text("canary")
try:
socket.create_connection(("127.0.0.1", 9), timeout=0.01)
except OSError:
pass
eval("1 + 1", {"__builtins__": {}}, {})
subprocess.run([sys.executable, "-m", "pip", "--version"], check=False)
subprocess.run(["pip", "install", "layerfault-synthetic-canary"], check=False)
try:
np.load("canary.npy", allow_pickle=True)
except Exception:
pass
return cls()