Skip to content

[RarFile] Prevent extraction of entire archive when file does not exist. - #188

Merged
garbear merged 1 commit into
xbmc:Piersfrom
78andyp:directory
Jul 28, 2026
Merged

garbear merged 1 commit into
xbmc:Piersfrom
78andyp:directory

Conversation

@78andyp

@78andyp 78andyp commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

CDirectoryFactory::Create() in Kodi core calls CFile::Stat() on every URL (including the archive root) before choosing an IDirectory.

That reaches CRARFile::Stat() → Open() with an empty m_pathinrar. The old code didn't check whether GetFileInRar() actually found a matching entry — it fell through to the "must be compressed, cache-extract it" branch regardless, and since the path was empty.

ArchiveExtract's fileToExtract.empty() check set all = true, extracting the entire archive (all files) just to answer a stat/exists probe.

The fix makes Open() fail fast when the requested path isn't a real file in the archive, so Stat() correctly falls through to its cheap DirectoryExists()/ArchiveList-based check instead.

Fix #187

@kodiai

kodiai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Decision: APPROVE

Issues: none

Evidence:

  • Review prompt covered 1 changed file.
Review Details
  • Files reviewed: 1

  • Findings: 0 critical, 0 major, 0 medium, 0 minor

  • Lines changed: +9 -2

  • Profile: strict (auto, lines changed: 11)

  • Contributor experience: profile-backed (using linked contributor profile guidance)

  • Review completed: 2026-07-28T16:17:09.151Z

  • Total wall-clock: 2m 35s

  • Phase timings:

    • queue wait: 1ms
    • workspace preparation: 773ms
    • retrieval/context assembly: 3.7s
    • executor handoff: 9.4s
    • remote runtime: 2m 18s
    • publication: 260ms (degraded: captured before publication completed)
  • Tokens: 18 in / 4,979 out | 0.1513

  • Keyword parsing: No keywords detected

  • Budget behavior: complete (within-budget).

  • Prompt budget: 6 sections, 0 trimmed, 0 bypassed, 0 trimmed tokens.

  • Cache behavior: 2 observations, 1 hits, 1 misses, 0 degraded, 0 bypassed.

  • Continuation behavior: 0 observations, 0 compacted, 0 fallback, 0 degraded, 0 bypassed.

@garbear garbear left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the failure mode is correctly handled. @kodiai please review.

@kodiai kodiai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decision: APPROVE

kodiai response

Decision: APPROVE
Issues: none

Evidence:

  • Early validation prevents extraction: src/RarFile.cpp:38-45 adds a guard that immediately returns nullptr when GetFileInRar() fails to locate the requested file in the archive, blocking any downstream extraction logic before it can trigger
  • Proper resource cleanup: The failure path correctly deletes the allocated RARContext (line 43) before returning nullptr, preventing memory leaks
  • Graceful fallback in Stat(): src/RarFile.cpp:417-427 already handles nullptr returns from Open() by falling back to DirectoryExists(), which uses the cheaper GetDirectory/ArchiveList verification path instead of extraction
  • Root cause eliminated: Without this check, an empty m_pathinrar (from a non-existent file) would reach the extraction branch, where an empty fileToExtract triggers all = true in the extraction engine, causing the entire archive to be unpacked just to answer a stat query (fixes #187)
  • Safe null handling: Close() at src/RarFile.cpp:204-223 safely handles nullptr context (lines 206-208 guard), so the Close(ctx) call at line 427 won't crash when ctx is nullptr
  • Correct error semantics: The Stat() function properly returns errno = ENOENT (line 434) when neither file nor directory exists, maintaining standard POSIX behavior

@78andyp

78andyp commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Thanks @garbear
I'm waiting for feedback from the bug reporter but it works here.

Who can merge addon PRs??
How do they then get updated by kodi - does that happen automatically if they are installed??

@garbear

garbear commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

I can merge. I can also cut a new release. Add-on manager will see the new version after a repo update.

@78andyp

78andyp commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Confirmed working by bug reporter - xbmc/xbmc#28768 (comment)

@garbear

garbear commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Nice. I'll do a release when I get a chance.

@garbear
garbear merged commit a15c1fd into xbmc:Piers Jul 28, 2026
7 checks passed
@78andyp

78andyp commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Thanks

@garbear

garbear commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Released version 22.0.4-Piers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rar files are being unpacked onto the storage

2 participants