From 006c22233c5e68298c31b67f31b2959b679cdfaa Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 4 Jun 2015 15:04:10 +0100 Subject: [PATCH] Bug 1167888 - better string length check in nsZipArchive::BuildFileList, r=smaug --- modules/libjar/nsZipArchive.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/libjar/nsZipArchive.cpp b/modules/libjar/nsZipArchive.cpp index 18b26e44c7b..507e1246539 100644 --- a/modules/libjar/nsZipArchive.cpp +++ b/modules/libjar/nsZipArchive.cpp @@ -644,8 +644,13 @@ MOZ_WIN_MEM_TRY_BEGIN if (!centralOffset) return NS_ERROR_FILE_CORRUPTED; - //-- Read the central directory headers buf = startp + centralOffset; + + // avoid overflow of startp + centralOffset. + if (buf < startp) + return NS_ERROR_FILE_CORRUPTED; + + //-- Read the central directory headers uint32_t sig = 0; while (buf + int32_t(sizeof(uint32_t)) <= endp && (sig = xtolong(buf)) == CENTRALSIG) {