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

Possible endless loop in mergeComplexNumberFormatMasks #1792

Closed
brainz80 opened this issue Jan 14, 2021 · 2 comments
Closed

Possible endless loop in mergeComplexNumberFormatMasks #1792

brainz80 opened this issue Jan 14, 2021 · 2 comments

Comments

@brainz80
Copy link
Contributor

brainz80 commented Jan 14, 2021

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Expected not to get stuck in do-while -loop.

What is the current behavior?

Gets stuck with e.g.

$numbers = array('434', '22222222222');
$masks = array('ka', ' 0', '00');

Callstack

image

Which versions of PhpSpreadsheet and PHP are affected?

Tested 1.16.0, 1.15.0 and 1.10.0

Possible fix

    private static function mergeComplexNumberFormatMasks($numbers, $masks)
    {
        $decimalCount = strlen($numbers[1]);
        $postDecimalMasks = [];

        do {
            $tempMask = array_pop($masks);
            $postDecimalMasks[] = $tempMask;
            $decimalCount -= strlen($tempMask);
        } while ($tempMask !== null && $decimalCount > 0);

        return [
            implode('.', $masks),
            implode('.', array_reverse($postDecimalMasks)),
        ];
    }
    
@brainz80
Copy link
Contributor Author

Made a pull-request of my fix: #1793

@MarkBaker
Copy link
Member

Fixed in PR #1793

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

No branches or pull requests

2 participants