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

[Crash] Renderers (isDrawingValuesAllowed func) crash - wrong data type cast causes host app to crash #5197

Open
sorinmiroiu97 opened this issue Sep 2, 2024 · 1 comment

Comments

@sorinmiroiu97
Copy link

What did you do?

We integrated the latest version of this library, as of the current time I'm writing this (v5.1.0), into our project for displaying some charts. There's an unusual behaviour, but a valid one in the project, that causes the app to crash because of a data cast from Double.infinite to Integer, but the this cast fails as infinite cannot be cast into an Int, and this code resides within the library.
The class in questions is BarLineScatterCandleBubbleRenderer and this is the place where it crashes:
open func isDrawingValuesAllowed(dataProvider: ChartDataProvider?) -> Bool { guard let data = dataProvider?.data else { return false } return data.entryCount < Int(CGFloat(dataProvider?.maxVisibleCount ?? 0) * viewPortHandler.scaleX) }

What did you expect to happen?

I would've expected for this CGFloat to be checked against CGFloat.infinity and CGFloat.nan and to return with a false in these cases out of the isDrawingValuesAllowed function.
Also I'd expect this check to be applied to all renderers as it can occur in the other files as well.

What happened instead?

The type cast fails and thus it crashes the host app.

DGCharts Environment

**DGCharts version/Branch/Commit Number:5.1.0
**Xcode version:Version 15.4 (15F31d)
**Swift version:5
**Platform(s) running DGCharts:iOS
**macOS version running Xcode:14.5 (23F79)

Demo Project

I'm not adding a demo project as I'm submitting a pull request so i need this ticket created in order to link the PR to this issue.

@sorinmiroiu97
Copy link
Author

I opened up a PR for this issue here: #5198
Thank you :D

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

No branches or pull requests

1 participant