mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
ff0e20453f
Fixed three bugs that caused infinite loops in GCD calculations: 1. mpz_set_int() didn't shrink sz when setting a smaller value. mpz_realloc() only grows allocations, so setting a 1-limb value to an mpz_t with sz=3 would leave sz=3, breaking algorithms that depend on correct sz values. 2. mpz_set_uint64() had the same issue. 3. mpz_gcd() used mpz_init_set() which preserves the sign. GCD should work with absolute values since gcd(a,b) = gcd(|a|,|b|). With negative inputs, the sign would oscillate during mod operations, preventing the Euclidean algorithm from converging. 4. mpz_div_2exp() when e==0 and z==x would corrupt data by calling mpz_init_heap() which overwrites z->p before copying from x. These bugs were discovered via ClusterFuzz with complex rational number calculations. Co-authored-by: Claude <noreply@anthropic.com>