Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault (index oob) in ext/bcmath/libbcmath/src/convert.c:155 #16265

Open
YuanchengJiang opened this issue Oct 6, 2024 · 3 comments

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
$variation_array = array(
'float -12.3456789000e10' => -12.3456789000e10,
);
$fusion = $variation_array;
require(__DIR__ . "/run_bcmath_tests_function.inc");
$dividends = ["15", "-15", "1", "-9", "14.14", "-16.60", "0.15", "-0.01"];
run_bcmath_tests($dividends, $fusion, "/", bcdiv(...));

Resulted in this output:

/php-src/ext/bcmath/libbcmath/src/convert.c:155:68: runtime error: index 8791595 out of bounds for type 'const unsigned char[100]'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /php-src/ext/bcmath/libbcmath/src/convert.c:155:68

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

@nielsdos
Copy link
Member

nielsdos commented Oct 6, 2024

Likely same root cause as #16262

@cmb69
Copy link
Member

cmb69 commented Oct 6, 2024

Simplified reproducer:

bcdiv("-0.01", -12.3456789000e10, 9);

@nielsdos
Copy link
Member

nielsdos commented Oct 6, 2024

No, slightly different cause than #16262.
The problem here is that quot_real_arr_size is 0, so the loop for (i = 0; i < quot_real_arr_size - 1; i++) { goes OOB.
However, the loop must write bytes because otherwise the numbers in bc_num are uninitialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants