You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potential crash / out-of-bounds iterator dereference in HttpFileImpl::save() #2655
Found a potential invalid iterator dereference while fuzzing in HttpFileImpl::save(const std::string &path) in lib/src/HttpFileImpl.cc. HttpFileImpl::save(const std::string &path) in lib/src/HttpFileImpl.cc uses the three-iterator overload of std::equal to check whether the canonical destination is inside the configured upload directory:
if (!std::equal(fsUploadDir.begin(),
fsUploadDir.end(),
fsSaveToPath.begin()))
This overload requires the second range to contain at least as many elements as the first. That condition is not guaranteed here. When a traversal filename resolves to a strict ancestor of the upload directory, the destination has fewer path components. std::equal may then dereference an iterator past fsSaveToPath.end(), resulting in undefined behavior. With libstdc++ assertions enabled (-D_GLIBCXX_ASSERTIONS), this reproduces as a process abort:
The canonical destination becomes /tmp/drogon_app/a/b/c, which has fewer path components than the upload directory.
Build Drogon's HttpFileImpl.cc with -D_GLIBCXX_ASSERTIONS and run the reproducer. The process aborts during the std::equal comparison.
Expected behavior
The traversal attempt should be rejected safely, with save() returning -1. Valid uploads, including those targeting nested subdirectories, should continue to work.
Use the four-iterator overload of std::mismatch for a bounds-safe component-wise prefix check:
auto mismatch = std::mismatch(
fsUploadDir.begin(),
fsUploadDir.end(),
fsSaveToPath.begin(),
fsSaveToPath.end()
);
if (mismatch.first != fsUploadDir.end())
{
LOG_ERROR
<< "Attempt writing outside of upload directory detected. Path: "
<< fileName_;
return -1;
}
Unlike four-iterator std::equal, this allows the destination to contain additional components, preserving valid nested uploads while safely rejecting shorter or non-matching paths.
I can submit a PR with the proposed fix and regression tests if this approach looks reasonable.
Activity
shadye-6 commentedon Oct 31, 2026
i've submitted a PR addressing this issue.
PR: #2656 – [Fix out-of-bounds iterator dereference in HttpFileImpl::save()](#2656)
The PR includes the
std::mismatchfix and regression tests covering traversal paths and valid nested uploads. suggestions or changes will be appreciated.