哈基米 b6515b1415
fix(skills): reject unextractable archive member trees (#8302)
* fix(skills): reject unextractable archive member trees

An archive with a file that is also an ancestor directory, or a member
that normalizes to the extraction root, crashed extraction with OSError
and the scan preflight raised IndexError on an empty member name, so the
install route returned 500 instead of a validation 400. Validate the
whole member tree before writing anything, comparing NFC+casefolded keys
so case-insensitive and normalization-sensitive filesystems cannot create
the same collision, and enforce the export path/depth/segment limits so
overlong paths fail as validation errors instead of OS errors.

* fix(skills): align archive depth limit with export

export.py limits paths to 32 components relative to the skill root; an
archive member adds the enclosing skill directory, so a valid 32-component
export was rejected on reinstall. Allow 33 archive components and cover the
boundary with a round-trip extraction test.

* fix(skills): reject folded duplicates and enforce the host path limit

Two case-variant file entries collapse into one file on a case-insensitive
filesystem, and a long member path can still exceed the destination
filesystem limit once the staging root is prefixed, raising ENAMETOOLONG
after a partial write. Reject duplicate folded file keys and validate the
full destination path before extraction.

* fix(skills): measure host paths in platform units and guard publication

Win32 limits are counted in UTF-16 code units and long paths are opt-in,
while the previous check compared UTF-8 bytes against 260. Measure with the
platform units and read LongPathsEnabled. Also reject a publication staging
path that exceeds the host limit and translate ENAMETOOLONG during staging
into the installer validation error.

* fix(skills): reject nested members whose staged path is too long

The staging temp-dir name lengthens every member path, so a nested member can
exceed the filesystem path limit while the skill root and the final path fit.
shutil.copytree wraps a child's ENAMETOOLONG in shutil.Error, which carries no
errno or winerror, so the existing translation let it escape as a 500. Check
each member's full staging path before copying.
2026-11-18 09:57:14 +08:00
..