Skip to content

fix: robust against corrupted downloads#101

Merged
jlblancoc merged 1 commit into
developfrom
fix-recover-from-corrupted-downloads
May 19, 2026
Merged

fix: robust against corrupted downloads#101
jlblancoc merged 1 commit into
developfrom
fix-recover-from-corrupted-downloads

Conversation

@jlblancoc
Copy link
Copy Markdown
Member

@jlblancoc jlblancoc commented May 18, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of remote resource acquisition: downloads are skipped when cached, and platform-specific download handling reduces failures.
    • Added automatic retry on corrupt archive extraction (one re-download + retry) to recover transient errors.
    • Ensured cleanup of partially extracted or corrupted files so subsequent downloads and extractions start from a clean state.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a29ba1d7-adc4-4c30-ae31-7cc298a1fa49

📥 Commits

Reviewing files that changed from the base of the PR and between 1d80ad2 and 9545262.

📒 Files selected for processing (1)
  • modules/simulator/src/RemoteResourcesManager.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • modules/simulator/src/RemoteResourcesManager.cpp

📝 Walkthrough

Walkthrough

RemoteResourcesManager extracts download logic into a local lambda, downloads only when cache is missing, retries ZIP extraction once after re-downloading if the first attempt fails, and removes partial extraction directories and corrupt ZIP files on unzip failure.

Changes

Remote resource retry and cleanup

Layer / File(s) Summary
Platform networking/process includes
modules/simulator/src/RemoteResourcesManager.cpp
Adds non-Windows-only sys/wait.h and unistd.h includes to support fork/wait download logic.
ZIP URI split refactor
modules/simulator/src/RemoteResourcesManager.cpp
Replaces structured binding with explicit locals isZipPkg, zipOrFileURI, internalURI for ZIP URI decomposition.
Download lambda and ZIP retry
modules/simulator/src/RemoteResourcesManager.cpp
Adds a doDownload lambda that downloads via wget (fork/execlp on non-Windows, system on Windows) only when cache is missing, and wraps ZIP handling in a try-catch to re-download and retry once on first failure.
Cleanup on unzip failure
modules/simulator/src/RemoteResourcesManager.cpp
Deletes partially extracted output directory and removes the corrupt ZIP file when unzip fails to allow subsequent retries to start clean.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops where downloads roam,
It fetches zips then brings them home,
If extraction breaks on try number one,
It re-gets the file and tries again — then done. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: robust against corrupted downloads' directly reflects the main change: adding retry logic and cleanup when ZIP package handling fails due to corruption.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-recover-from-corrupted-downloads

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modules/simulator/src/RemoteResourcesManager.cpp (1)

117-123: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Shell command injection risk in download command construction

Line 118 inserts zipOrFileURI directly into a system() command without robust shell escaping. A crafted URI can break command parsing or execute unintended shell tokens.

Suggested hardening diff
+	auto shellQuote = [](const std::string& s) {
+		std::string out = "'";
+		for (char c : s)
+		{
+			if (c == '\'')
+				out += "'\\''";
+			else
+				out.push_back(c);
+		}
+		out += "'";
+		return out;
+	};
+
 	auto doDownload = [&]()
 	{
-		const auto cmd =
-			mrpt::format("wget -q -O \"%s\" %s", localFil.c_str(), zipOrFileURI.c_str());
+		const auto cmd = mrpt::format(
+			"wget -q -O %s %s", shellQuote(localFil).c_str(),
+			shellQuote(zipOrFileURI).c_str());
🤖 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 `@modules/simulator/src/RemoteResourcesManager.cpp` around lines 117 - 123, The
download command builds a shell string with zipOrFileURI and passes it to
::system (cmd) which allows shell injection; replace this by avoiding shell
invocation: use a dedicated HTTP client (e.g., libcurl) or a spawn/exec variant
that accepts argv to fetch the URI instead of formatting it into cmd, and remove
the use of ::system(cmd.c_str()). Update the code around the cmd variable, the
::system call, and the surrounding download logic (references: zipOrFileURI,
localFil, cmd, ::system, MRPT_LOG_INFO_STREAM) so the URI is passed as an
unescaped argument to a safe downloader API or properly validated/escaped before
use.
🤖 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.

Outside diff comments:
In `@modules/simulator/src/RemoteResourcesManager.cpp`:
- Around line 117-123: The download command builds a shell string with
zipOrFileURI and passes it to ::system (cmd) which allows shell injection;
replace this by avoiding shell invocation: use a dedicated HTTP client (e.g.,
libcurl) or a spawn/exec variant that accepts argv to fetch the URI instead of
formatting it into cmd, and remove the use of ::system(cmd.c_str()). Update the
code around the cmd variable, the ::system call, and the surrounding download
logic (references: zipOrFileURI, localFil, cmd, ::system, MRPT_LOG_INFO_STREAM)
so the URI is passed as an unescaped argument to a safe downloader API or
properly validated/escaped before use.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 27cc44a3-fac1-4257-b393-e373953beee7

📥 Commits

Reviewing files that changed from the base of the PR and between 51ed42f and 1d80ad2.

📒 Files selected for processing (1)
  • modules/simulator/src/RemoteResourcesManager.cpp

@jlblancoc jlblancoc force-pushed the fix-recover-from-corrupted-downloads branch from 1d80ad2 to 9545262 Compare May 19, 2026 05:24
@jlblancoc jlblancoc merged commit 6999236 into develop May 19, 2026
12 checks passed
@jlblancoc jlblancoc deleted the fix-recover-from-corrupted-downloads branch May 19, 2026 05:36
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.

1 participant