Repository navigation
fix(subjects): a descriptor path past the file-name limit is reported as a missing descriptor - #1078
Conversation
… as a missing descriptor (intel#1022) `load_subject` probed the descriptor with `Path.is_file()`, which on Linux raises `OSError: [Errno 36] File name too long` for a component over the limit. `subjects show` and `subjects run` catch only `ValueError` and `FileNotFoundError`, so the user got a traceback where a missing descriptor gets `cannot load subject: <path>`. `subjects list --subjects-root` had the same traceback from `Path.is_dir()`. `_load_mapping` now reads an `OSError` from that probe as a missing file and raises `FileNotFoundError(path)` when its errno is ENAMETOOLONG or its winerror is 123, 206 or 1921. `subjects list` applies the same check to the root and refuses it as not a directory. Any other `OSError`, a permission or I/O error on an existing path, still propagates. The suffix check still comes after the probe, so a long name with an unsupported suffix is reported as missing, as before. The tests are in a new file because `tests/test_subjects.py` is at its growth-ratchet size. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1078 +/- ##
=======================================
Coverage 95.92% 95.93%
=======================================
Files 450 451 +1
Lines 59527 59622 +95
Branches 10265 10273 +8
=======================================
+ Hits 57101 57197 +96
+ Misses 1507 1505 -2
- Partials 919 920 +1
🚀 New features to boost your workflow:
|
…be as not a directory Codecov names the ENAMETOOLONG handler in cmd_subjects_list as not covered: newer Pythons make Path.is_dir return False for a long name, so the 5000-character root never reaches the handler there. The new test makes is_dir raise ENAMETOOLONG, so the handler runs on every Python version. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
Review points answered at |
napetrov
left a comment
There was a problem hiding this comment.
Change class: LOCAL (head 0a92915)
- Contract: none
- Responsibility: none
- Dependency: none
- Review depth: skim: local change, check diff + tests
- Coverage gaps: none
One documentation nit. I checked the loader and both CLI path probes, including an actual inaccessible descriptor on Python 3.14.
Focused tests on 0a9291588: 11 passed in 0.22s. CI on head 0a92915: 0 failing Actions jobs; merge base 36075a0 is the base tip.
intel#1022) Path.is_file() turns the permission error into False on 3.14, so a descriptor below an unsearchable directory raises FileNotFoundError there, on the base as well. The changelog said a permission or I/O error on an existing path always propagates. Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
xaleryb
left a comment
There was a problem hiding this comment.
Approved on dea8d90. Ran the earlier head 0a92915 merged with main: tests/test_subjects_long_name.py has 9 failures and 2 passes on main's code (the two passes pin PermissionError) and 11 passes on the head; widening the handler to any OSError turns the PermissionError test red; the full suite, ruff, mypy, bandit and the growth, comment-block and docs gates are clean. dea8d90 only qualifies the changelog sentence for Python 3.14 (napetrov's note); the code is unchanged. CI is green on this head.
Summary
subjects show,subjects runandsubjects list --subjects-rootend in anOSErrortraceback when the path they are given has a component over the file-name limit (255 bytes on Linux). Onmain,_load_mapping(Path("x" * 5000 + ".json"))raisesOSError: [Errno 36] File name too longfrompath.is_file()indokimi/dokimi/subjects/loader.py;cmd_subjects_showandcmd_subjects_runcatch onlyValueErrorandFileNotFoundError, so a missing descriptor getsError: cannot load subject: <path>(exit 2) and this one gets the traceback.cmd_subjects_listhas the same cause for its root:Path.is_dir()on--subjects-rootwith a 300-character component raisesOSError: [Errno 36].Of the fix options the issue lists (read the
OSErroras a missing file in_load_mapping, or catch it at the call sites), this takes the first: one place, and a later caller ofload_subjectis covered. Only a name-too-long error is read as missing (ENAMETOOLONG, or on Windowswinerror123, 206 or 1921); a permission or I/O error on an existing path still propagates, since calling it "missing" would give a wrong message.Closes #1022
The scorecard digests have the same cause on another input and are handled by #1023 (refs #911); they are not touched here.
Changes
dokimi/dokimi/subjects/loader.py:_load_mappingtreats anOSErrorfrom theis_file()probe as a missing file, raisingFileNotFoundError(path), whenname_too_longholds. The probe still comes before the suffix check, so a long name with an unsupported suffix is reported as missing, as before.dokimi/dokimi/commands/subjects.py:cmd_subjects_listapplies the same check to--subjects-rootand refuses it with--subjects-root is not a directory: <path>(exit 2).dokimi/tests/test_subjects_long_name.py(new;tests/test_subjects.pyis at its growth-ratchet size): the load, command and list cases above, a 300-character component underPATH_MAX, the unsupported-suffix order, the Windows codes, aPermissionErrorthat must still propagate from both probes, and asubjects listroot whoseis_dir()raisesENAMETOOLONG(on a Python wherePath.is_dir()returnsFalsefor a long name, the 5000-character root never reaches the handler, so this case makes it run on every version).Risk
Only inputs that raised
OSErrorchange: a descriptor path or--subjects-rootwith a component over the file-name limit now exits 2 withcannot load subject: ...or--subjects-root is not a directory: ...instead of a traceback. Paths of normal length, missing descriptors, the suffix error and otherOSErrors behave as before.Open PRs #956 and #954 also change
commands/subjects.py(an error message incmd_subjects_run, the--max-tokensoption inregister) and #956 one message inloader.py(_member_specs); none touches the lines changed here, so a merge with either is clean.Testing
On a Linux review host, at
0a929158(onmain36075a0):make ci-local: 36 passed, 0 failed, 14 skipped (steps that need another runner, Docker, micromamba, semgrep or a PR event). 24494 tests passed, 19 skipped; changed-line coverage 100%; mutation of changed lines: 17 of 17 killed.main's code,tests/test_subjects_long_name.pygives8 failed, 2 passed, first onOSError: [Errno 36] File name too longfromPath.is_file(); the two that pass are thePermissionErrortests, which pin what must not change. Here: 11 passed.subjects listtest: re-raising everyOSErrorfrom the root probe incmd_subjects_listfails it (and the 5000-character root test, on this Python 3.13)._load_mappingfails 7 tests (the load, command, 300-character and Windows cases); widening it to anyOSErrorfails thePermissionErrortest; emptying the Windows codes fails the three Windows cases; moving the suffix check before the probe fails the unsupported-suffix test; dropping or widening the check incmd_subjects_listfails the list test and the listPermissionErrortest respectively.winerror).Open questions
None.
Revert
A plain revert restores the traceback. Nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)