KEMBAR78
IMAGE: Fix MSRLEDecoder if pitch > width by mikrosk · Pull Request #4832 · scummvm/scummvm · GitHub
Skip to content

Conversation

@mikrosk
Copy link
Contributor

@mikrosk mikrosk commented Mar 22, 2023

Fixes 14356.

It's possible that there's more bugs like this but I can't test it as this was the first occasion where I saw something corrupted.

For instance MSRLE4Decoder::decode4 uses a slightly inefficient but safe getBasePtr(x, y) (which implicitly uses surface pitch) but I think this line:

byte *output_end = (byte *)_surface->getBasePtr(_surface->w, y);

is wrong -- technically speaking, nothing will be written past the allocated memory but the algorithm is writing past width pixels in the unused surface area.

@lephilousophe
Copy link
Member

Your fix seems incomplete.
It doesn't prevent writing in the unused surface area when doing pixel copies and pixel runs and I am not sure they can't cross lines.

@mikrosk
Copy link
Contributor Author

mikrosk commented Mar 23, 2023

@lephilousophe can you be more specific? I don't understand the code that much but output_end (which is terminated by width, not by pitch) should handle all overflows? (the example I posted in PR description is from another class where such problem can occur, yes).

@lephilousophe
Copy link
Member

lephilousophe commented Mar 23, 2023

output_end is the end of the image.
If you are at the end of a line and start copying n bytes, I think it should wrap to the beginning of the next line.
In the case where pitch != w the data will continue beyond w but not wrap to the next line: it will end up in the unused area.

I must say that I don't know RLE and that this cross line coding may be forbidden by the specification.

@mikrosk
Copy link
Contributor Author

mikrosk commented Mar 23, 2023

Ah, right, now I see what you mean. Judging from the value == 0 which explicitly marks end of line I'd say this scenario shouldn't be supported but I'm also not 100% sure. The description isn't very explicit about this either but since the deltas are just byte values, I'd say there's a pretty good chance they did not consider having pictures with width less then 256 pixels filled over to the next line.

I'd argue that if this assumption turns out to be false, I'd be the first to notice as it seems that Atari is the only backend having w != pitch for 8bpp graphics.

Btw do you know how to quickly test the 4-bit variant? I could fix & test that one as well.

@lephilousophe
Copy link
Member

Btw do you know how to quickly test the 4-bit variant? I could fix & test that one as well.

I don't. :(

@mikrosk
Copy link
Contributor Author

mikrosk commented Mar 23, 2023

Maybe @sev- does, he added it in d35cdf5, only 7 years ago. :-) Looking at https://docs.scummvm.org/en/latest/help/release.html#myst-ery-u-f-o-s-release-2016-10-17 doesn't show me anything concrete to identify the codec...

@sev-
Copy link
Member

sev- commented Mar 29, 2023

IIRC, that was for the GNAP engine.

@mikrosk
Copy link
Contributor Author

mikrosk commented Mar 30, 2023

Tried to run U.F.O.s on my Linux and while it has quite amusing animations and gameplay, I wasn't able to hit the decode4 function.

Since I know better than fixing code which I can't test afterwards, I propose to take this PR as is since it fixes something which I can verify and doesn't seem to break anything else.

@ccawley2011
Copy link
Member

The testbed engine has a generic video player that can be used for testing codec changes. It's currently hardcoded to use the QuickTime decoder, but that can be swapped with a different one with relative ease. The testbed changes in PR #4736 improve this feature further.

@mikrosk mikrosk force-pushed the msrledecoder_pitch branch from c5271ab to 61b1220 Compare May 10, 2023 22:06
@sev-
Copy link
Member

sev- commented May 14, 2023

Okay, thank you!

@sev- sev- merged commit 67aea06 into scummvm:master May 14, 2023
@mikrosk mikrosk deleted the msrledecoder_pitch branch May 17, 2023 18:44
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