fix: robust against corrupted downloads#101
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRemoteResourcesManager 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. ChangesRemote resource retry and cleanup
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
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 winShell command injection risk in download command construction
Line 118 inserts
zipOrFileURIdirectly into asystem()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
📒 Files selected for processing (1)
modules/simulator/src/RemoteResourcesManager.cpp
1d80ad2 to
9545262
Compare
Summary by CodeRabbit