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

formats/cassimg.cpp: Fixed bad image crash in tap format (MT8952) #13294

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

holub
Copy link
Contributor

@holub holub commented Jan 29, 2025

I hope this time the fix is more solid and non-destructive

@@ -127,6 +127,7 @@ class cassette_image
uint32_t sample_frequency = 0;
int header_samples = 0;
int trailer_samples = 0;
int (*fill_wave_ext)(int16_t *, int, const uint8_t *, int) = nullptr;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I can change signature for all existing fill_wave

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm waiting for consensus. Have this ^^^ implemented locally or can easily refactor to loading error without crash if you insist.

@cuavas
Copy link
Member

cuavas commented Jan 29, 2025

Can you explain what the issue is, how it happens, and what this change is supposed to do to deal with it? Alternatively, would it be better to just reject these bad tape images? Trying to “fix” or gracefully handle bad input has been a constant source of bugs over the years, which is why software is increasingly moving to an approach of rejecting bad input outright.

@ajrhacker
Copy link
Contributor

software is increasingly moving to an approach of rejecting bad input outright

Has MAME been doing anything specific in this direction, or is it just a trend witnessed elsewhere?

@holub
Copy link
Contributor Author

holub commented Jan 29, 2025

It's pretty much explained in the deleted comment.
When we calculate output size initially it's based on the headers in the input which can request more data than actual image size.
Wave production uses on same input but now without "knowing" how much size is available.

Rejecting this images is the possibility, but with this change we are in better shape, as we can try to convert as much as we can and potentially that will (and proven "is") be enough.

@cuavas
Copy link
Member

cuavas commented Jan 29, 2025

software is increasingly moving to an approach of rejecting bad input outright

Has MAME been doing anything specific in this direction, or is it just a trend witnessed elsewhere?

Yes, MAME is a lot better at rejecting rather than crashing on thing like bad ZIP, PNG and ICO files. There’s also more error checking in cartridge loading, etc. to reject invalid input.

But it’s a trend in software in general, as the realisation has set in that “be liberal in what you accept and strict in what you produce” has cause more problems than it solves. In particular, there’s inconsistency in how different software interprets the same invalid input, and all manner of bugs caused by the complexity of trying to do something useful with invalid input.

@holub
Copy link
Contributor Author

holub commented Jan 30, 2025

Another though:
in theory switching to error at this point can make some existing dump wrong.
Scenario is: image has a header which requesting 1 byte more than needed, in the current state that's not enough to couse illegal access exception. So currently we can have working image but it will cause error after change to strict validation.

@holub
Copy link
Contributor Author

holub commented Jan 30, 2025

Maybe we can osd warning about wrong image. Not sure if a lot of people cares about logs - that will reduce false bugrepors.

@mgarlanger
Copy link
Contributor

What about updating the ones which are still using legacy cassette routines, to use the newer routines? I did this for the Heath H8/H88 file (although my PR is still waiting for a review - #13250). This removes the need to determine the size up front (the base routines resize as needed).

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

Successfully merging this pull request may close these issues.

4 participants