Calculate code_store safely in CGifLZWDecoder::Decode
BUG=682628
Change-Id: I8e88cc0c8392b078afb73f9549ea4dea9a5717fd
Reviewed-on: https://pdfium-review.googlesource.com/2390
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcodec/lgif/fx_gif.cpp b/core/fxcodec/lgif/fx_gif.cpp
index 93db181..d62dacb 100644
--- a/core/fxcodec/lgif/fx_gif.cpp
+++ b/core/fxcodec/lgif/fx_gif.cpp
@@ -114,7 +114,17 @@
FXSYS_strncpy(err_msg_ptr, "Decode Error", GIF_MAX_ERROR_SIZE - 1);
return 0;
}
- code_store |= (*next_in++) << bits_left;
+ pdfium::base::CheckedNumeric<uint32_t> safe_code = *next_in++;
+ safe_code <<= bits_left;
+ safe_code |= code_store;
+ if (!safe_code.IsValid()) {
+ if (err_msg_ptr) {
+ FXSYS_strncpy(err_msg_ptr, "Code Store Out Of Range",
+ GIF_MAX_ERROR_SIZE - 1);
+ }
+ return 0;
+ }
+ code_store = safe_code.ValueOrDie();
avail_in--;
bits_left += 8;
}