shepsci/kaggle-skill / skills/kaggle
kaggle
FlaggedUnified Kaggle skill. Use when the user explicitly mentions Kaggle, kaggle.com, a Kaggle URL, Kaggle competitions, Kaggle datasets/models/notebooks, Kaggle forums/discussions/writeups, Kaggle benchmarks, hackathons hosted on Kaggle, Kaggle badges, or Kaggle account setup. Do not use for generic ML, GPU/TPU, notebook, dataset, benchmark, or data-science tasks unless the user clearly ties them to Kaggle.
shared/safe_extract.py
View on GitHub#!/usr/bin/env python3
"""Extract a zip archive without letting any member leave the target folder.
python3 shared/safe_extract.py data.zip ./data
Kaggle archives are untrusted input. Every member's resolved path is checked
before anything is written, and symlink members are refused (exit status 5).
"""
from __future__ import annotations
import os
import stat
import sys
import zipfile
from pathlib import Path
if __package__ in (None, ""):
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from shared import untrusted # noqa: E402
class UnsafeArchiveError(ValueError):
"""A member would land outside the target folder, or is a symlink."""
def __init__(self, reason: str, member: str):
super().__init__(f"{reason}: {member!r}")
self.reason = reason
self.member = member
def safe_extract(archive: Path, dest: Path) -> list[str]:
"""Extract ``archive`` into ``dest``. Returns the member names written.
Raises UnsafeArchiveError (a ValueError) if a member would resolve outside
``dest`` or is a symlink. Nothing is written in that case.
"""
dest_real = os.path.realpath(dest)
with zipfile.ZipFile(archive) as zf:
members = zf.infolist()
for info in members:
target = os.path.realpath(os.path.join(dest_real, info.filename))
if not (target == dest_real or target.startswith(dest_real + os.sep)):
raise UnsafeArchiveError("member escapes the target folder", info.filename)
if stat.S_ISLNK(info.external_attr >> 16):
raise UnsafeArchiveError("member is a symlink", info.filename)
os.makedirs(dest_real, exist_ok=True)
zf.extractall(dest_real)
return [info.filename for info in members]
def main(argv: list[str] | None = None) -> int:
args = sys.argv[1:] if argv is None else argv
if len(args) != 2 or args[0] in ("-h", "--help"):
print("Usage: safe_extract.py <archive.zip> <dest-dir>")
return 0 if args and args[0] in ("-h", "--help") else 2
archive, dest = Path(args[0]), Path(args[1])
try:
names = safe_extract(archive, dest)
except UnsafeArchiveError as exc:
print(f"error: refusing to extract: {exc.reason}:", file=sys.stderr)
# The member name is chosen by whoever built the archive.
untrusted.emit_text(exc.member, source="local", tool="safe_extract", file=sys.stderr)
return 5
except (zipfile.BadZipFile, OSError) as exc:
print(f"error: could not extract the archive ({type(exc).__name__})", file=sys.stderr)
return 1
print(f"extracted {len(names)} file(s)")
return 0
if __name__ == "__main__":
sys.exit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |