Merge pull request #5894 from jayzed80/fix/eps-bitshift-min

fix(eps): bitshift by the most negative integer no longer overflows on negation
This commit is contained in:
BFlat
2026-11-06 15:34:06 +08:00
committed by GitHub
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -816,7 +816,7 @@ impl<'a> Interp<'a> {
},
Bitshift => {
let (s, v) = (self.pop_int()?, self.pop_int()?);
let r = if s >= 0 { v.checked_shl(s.min(63) as u32) } else { v.checked_shr((-s).min(63) as u32) };
let r = if s >= 0 { v.checked_shl(s.min(63) as u32) } else { v.checked_shr(s.saturating_neg().min(63) as u32) };
self.push(Obj::Int(r.unwrap_or(0)))?;
}
True => self.push(Obj::Bool(true))?,
+7
View File
@@ -1400,3 +1400,10 @@ fn stored_graphics_states_use_up_the_memory_budget() {
assert!(r.warnings.iter().any(|w| w.contains("uses too much memory")), "{body}: {:?}", r.warnings);
}
}
/// `bitshift` by the most negative integer shifts right by everything, not a negation overflow.
#[test]
fn bitshift_by_the_most_negative_integer_does_not_panic() {
let r = read("0 0 10 10 rectfill 1 -9223372036854775808 bitshift pop -1 -9223372036854775808 bitshift pop");
assert_eq!(objects(&r.document).len(), 1, "{:?}", r.warnings);
}