c++ - Division constant leak
- Piotr Grochowski (37/37) Apr 07 2023 This glitching called Division constant leak is more tricky to
This glitching called Division constant leak is more tricky to reproduce than Bad multiplication, Infinite compiling, and Structure initalization corruption. Division constant leak is a glitching that only occurs with *optimizations* (-o). ```d #include <vector> #include <iostream> int main(int argc,char**argv){ size_t _0=argc>>15; long o=100; std::vector<long> v(&o,&o+1); if(v[_0/3]==v[0]){o=v[0];} std::cout<<o; } ``` It results in the constant -1431655765 (0xAAAAAAAB) being output, being the division constant being leaked. With other denominators it could leak another constant, such as with the denominator of 5, it outputs -858993459 (0xCCCCCCCD). The Division constant leak has also been observed to cause crashes when the division constant leaks to the array index: ```d #include <vector> #include <iostream> int main(int argc,char**argv){ std::vector<long> u; size_t _0=argc>>15; long o=100; std::vector<long> v(&o,&o+1); size_t _5 = _0+5; if(v[_0/3]==v[_5/5-1]){ u.push_back(0); o=v[_5/5-1]; } std::cout<<o; } ```
Apr 07 2023