summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2025-04-15 22:52:52 +0200
committerSebastian Rasmussen <sebras@gmail.com>2025-04-16 13:03:52 +0200
commit14725d251f5dbe00d759c2219692c90708f4c57b (patch)
tree162438e52773172a6833f6b26f6e59e873d871f6
parent28592e822029d9f0d2ae8246a82c1f2ed054f91b (diff)
Bug 708455: Handle case in ps functions where integers cause a floating point exception.
This happens when computing INT_MIN / -1, that is -2147483648 / -1, which ought to result in 2147483648. Unfortunately that result is larger than INT_MAX. Approximate the result by setting it to INT_MAX.
-rw-r--r--source/pdf/pdf-function.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/source/pdf/pdf-function.c b/source/pdf/pdf-function.c
index ccc179d3a..2810914d5 100644
--- a/source/pdf/pdf-function.c
+++ b/source/pdf/pdf-function.c
@@ -1,4 +1,4 @@
-// Copyright (C) 2004-2024 Artifex Software, Inc.
+// Copyright (C) 2004-2025 Artifex Software, Inc.
//
// This file is part of MuPDF.
//
@@ -493,10 +493,15 @@ ps_run(fz_context *ctx, psobj *code, ps_stack *st, int pc)
case PS_OP_IDIV:
i2 = ps_pop_int(st);
i1 = ps_pop_int(st);
- if (i2 != 0)
- ps_push_int(st, i1 / i2);
- else
+ if (i2 == 0) {
ps_push_int(st, DIV_BY_ZERO(i1, i2, INT_MIN, INT_MAX));
+ }
+ else if (i1 == INT_MIN && i2 == -1) {
+ ps_push_int(st, INT_MAX);
+ }
+ else {
+ ps_push_int(st, i1 / i2);
+ }
break;
case PS_OP_INDEX:
@@ -544,10 +549,15 @@ ps_run(fz_context *ctx, psobj *code, ps_stack *st, int pc)
case PS_OP_MOD:
i2 = ps_pop_int(st);
i1 = ps_pop_int(st);
- if (i2 != 0)
- ps_push_int(st, i1 % i2);
- else
+ if (i2 == 0) {
ps_push_int(st, DIV_BY_ZERO(i1, i2, INT_MIN, INT_MAX));
+ }
+ else if (i1 == INT_MIN && i2 == -1) {
+ ps_push_int(st, 0);
+ }
+ else {
+ ps_push_int(st, i1 % i2);
+ }
break;
case PS_OP_MUL: