This seems quite unsafe; these should be asserted throughout and the documentation should mention the 32-bit upper limit.