fix AccessDeniedException при чтении#625
Conversation
📝 WalkthroughWalkthrough
MDClasses filesystem traversal fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDClasses.java`:
- Around line 292-296: The parent-name extraction in MDClasses is still unsafe
for files directly under the filesystem root because
path.getParent().getFileName() can be null and then .toString() throws. Update
the parentName handling in MDClasses to mirror the existing parentParentName
guard by checking both getParent() and getFileName() before converting to a
string, so traversal over "/" and other root-level files does not fail.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 57776c06-3a3c-4f28-8a26-a7e3f2b3b391
📒 Files selected for processing (1)
src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDClasses.java
| var parentName = path.getParent().getFileName().toString(); | ||
| var parentParentName = ""; | ||
| if (path.getParent().getParent() != null && path.getParent().getParent().getFileName() != null) { | ||
| parentParentName = path.getParent().getParent().getFileName().toString(); | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
NPE risk when a file resides directly under the filesystem root.
path.getParent().getFileName() returns null when the parent is a root path (e.g. /). Calling .toString() on it then throws NullPointerException. Since this PR specifically targets traversal of / and protected system paths (issue #609), a regular file located directly under / (parent /, getFileName() == null) would crash traversal — defeating the purpose of the fix. Note the grandparent computation at Line 294 already guards against a null getFileName(), but the parent at Line 292 does not.
🐛 Proposed fix to guard the parent name
- var parentName = path.getParent().getFileName().toString();
- var parentParentName = "";
- if (path.getParent().getParent() != null && path.getParent().getParent().getFileName() != null) {
- parentParentName = path.getParent().getParent().getFileName().toString();
- }
+ var parent = path.getParent();
+ var parentName = "";
+ if (parent != null && parent.getFileName() != null) {
+ parentName = parent.getFileName().toString();
+ }
+ var parentParentName = "";
+ if (parent != null && parent.getParent() != null && parent.getParent().getFileName() != null) {
+ parentParentName = parent.getParent().getFileName().toString();
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var parentName = path.getParent().getFileName().toString(); | |
| var parentParentName = ""; | |
| if (path.getParent().getParent() != null && path.getParent().getParent().getFileName() != null) { | |
| parentParentName = path.getParent().getParent().getFileName().toString(); | |
| } | |
| var parent = path.getParent(); | |
| var parentName = ""; | |
| if (parent != null && parent.getFileName() != null) { | |
| parentName = parent.getFileName().toString(); | |
| } | |
| var parentParentName = ""; | |
| if (parent != null && parent.getParent() != null && parent.getParent().getFileName() != null) { | |
| parentParentName = parent.getParent().getFileName().toString(); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/java/com/github/_1c_syntax/bsl/mdclasses/MDClasses.java` around
lines 292 - 296, The parent-name extraction in MDClasses is still unsafe for
files directly under the filesystem root because path.getParent().getFileName()
can be null and then .toString() throws. Update the parentName handling in
MDClasses to mirror the existing parentParentName guard by checking both
getParent() and getFileName() before converting to a string, so traversal over
"/" and other root-level files does not fail.
|


Описание
Исправление ошибки чтения недоступных каталогов
Связанные задачи
Closes: #609
Чеклист
Общие
gradlew precommit)Дополнительно
Summary by CodeRabbit