From e90061779637e4fe46798f2318fe26746d8dac78 Mon Sep 17 00:00:00 2001 From: Alex Rebert Date: Fri, 29 Oct 2021 09:17:40 -0400 Subject: [PATCH] Fix out-of-bounds read in FileSystemFilter::Cleanup Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33238 --- code/Common/FileSystemFilter.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/Common/FileSystemFilter.h b/code/Common/FileSystemFilter.h index 6782dd9e5..81576aa6c 100644 --- a/code/Common/FileSystemFilter.h +++ b/code/Common/FileSystemFilter.h @@ -300,13 +300,14 @@ private: const char separator = getOsSeparator(); for (it = in.begin(); it != in.end(); ++it) { + int remaining = std::distance(in.end(), it); // Exclude :// and \\, which remain untouched. // https://sourceforge.net/tracker/?func=detail&aid=3031725&group_id=226462&atid=1067632 - if ( !strncmp(&*it, "://", 3 )) { + if (remaining >= 3 && !strncmp(&*it, "://", 3 )) { it += 3; continue; } - if (it == in.begin() && !strncmp(&*it, "\\\\", 2)) { + if (it == in.begin() && remaining >= 2 && !strncmp(&*it, "\\\\", 2)) { it += 2; continue; }