Skip to content

Commit 9126f86

Browse files
OctavianGuzufacebook-github-bot
authored andcommitted
Prevent snprintf vulnerability
Summary: With a very big name for a `ParameterRange`, the `snprintf` call from `combination_name` can end up having a negative second parameter, causing a memory overflow, which can lead to a serious security issue. We can checking that the second parameter is always >= 0 and throw an exception if not. See the new GTEST. Reviewed By: mdouze Differential Revision: D46856956 fbshipit-source-id: 91c657ec028c462d4b808b595811342034e00133
1 parent 8ac4e41 commit 9126f86

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

faiss/AutoTune.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ std::string ParameterSpace::combination_name(size_t cno) const {
284284
char buf[1000], *wp = buf;
285285
*wp = 0;
286286
for (int i = 0; i < parameter_ranges.size(); i++) {
287+
FAISS_THROW_IF_NOT_MSG(
288+
buf + 1000 - wp >= 0, "Overflow detected in snprintf");
287289
const ParameterRange& pr = parameter_ranges[i];
288290
size_t j = cno % pr.values.size();
289291
cno /= pr.values.size();

0 commit comments

Comments
 (0)