1 Star 0 Fork 31

futa/ghostscript

forked from src-openEuler/ghostscript 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Bug-701721-jbig2dec-Fix-under-overflow-handling-in-arithmetic-integer-decoder.patch 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
wangchen 提交于 2020-09-03 15:54 +08:00 . Sync some patches from community
From ea9b3a676a516a603fabb593085d14a67356db6f Mon Sep 17 00:00:00 2001
From: Sebastian Rasmussen <sebras@gmail.com>
Date: Thu, 17 Oct 2019 01:48:00 +0200
Subject: [PATCH] Bug 701721: jbig2dec: Fix under/overflow handling in
arithmetic integer decoder.
The previous detection logic caused GCC's -Wlogical-op to trip.
Not only that, but the detection logic never took into account
that underflow is not possible (the worst case is V == INT32_MIN,
but offset is always > 0, so underflow cannot happen), nor take
varying offset values into account (hardcoded limits meant that
the offset was ignored even if it could not cause an overflow),
but instead could cause non-clamped values to be emitted.
This corrected logic adheres to the Annex A. Table A.1 in the specification.
---
jbig2dec/jbig2_arith_int.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/jbig2dec/jbig2_arith_int.c b/jbig2dec/jbig2_arith_int.c
index 7ad47ad..20b62df 100644
--- a/jbig2dec/jbig2_arith_int.c
+++ b/jbig2dec/jbig2_arith_int.c
@@ -130,8 +130,11 @@ jbig2_arith_int_decode(Jbig2Ctx *ctx, Jbig2ArithIntCtx *actx, Jbig2ArithState *a
V = (V << 1) | bit;
}
- /* make sure not to underflow/overflow 32 bit value */
- if (V < INT32_MAX - 4436 || V > INT32_MIN + 4436)
+ /* offset is always >=0, so underflow can't happen. */
+ /* avoid overflow by clamping 32 bit value. */
+ if (V > INT32_MAX - offset)
+ V = INT32_MAX;
+ else
V += offset;
V = S ? -V : V;
*p_result = V;
--
1.8.3.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/funited/ghostscript.git
git@gitee.com:funited/ghostscript.git
funited
ghostscript
ghostscript
master

搜索帮助