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
Software: Fix out of bounds accesses in CopyRegion #9321
Conversation
|
Hmm, per fifoci, my changes have shifted a lot of things in addition to fixing Rogue Squadron 2. Some changed horizontally (e.g. simpsons-game) and some changed vertically (sms-gc). As for RS2, rs2-glass looks incorrectly centered compared to on OGL (probably the same issue), and the HUD looks incorrectly colored and is missing blue dots in the minimap for rs2-skybox (OGL) and rs2-bumpmapping (OGL). rs2-zfreeze shows missing triangles, which is probably the same issue as rs3-bumpmapping (#9315 (comment)). I'm also not sure what's up with the messed up first frames (not a new issue, and an software renderer only thing). I did notice that there is a case for textures that uses a nonzero top and left, too, which might explain some of the shifts (I'm not entirely sure what all this code does or how it's supposed to work, though): dolphin/Source/Core/VideoCommon/TextureCacheBase.cpp Lines 1942 to 1956 in b4b2a12
|
| #include <cmath> | ||
| #include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This include doesn't seem necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's a leftover from testing. Though it's worth noting that both uses of CopyRegion start with vectors and use data() for it, so there isn't any strong reason to use raw pointers here (apart from performance maybe, but it's the software renderer...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was likely to keep it from needing to depend on a single container type, making it more flexible, since it can copy to any contiguous region of memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly... why does ScaleTexture make copies into and out of vectors? Wouldn't something like
const SWTexture* software_source_texture = static_cast<const SWTexture*>(src_texture);
SWTexture* software_dest_texture = static_cast<SWTexture*>(dst_framebuffer->GetColorAttachment());
CopyRegion(software_source_texture->GetData(), src_rect, software_dest_texture->GetData(), dst_rect);work? (Ignoring issues with the rectangles themselves).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it's because GetData() returns a pointer to u8 while this is supposed to operate on a pointer to Pixel (or something else) with a larger size. It still seems awkward to make a copy; is that actually required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
degasus, Stenzek, or some other graphic dev would be way more qualified to answer the why here than me. But at a glance, I agree.
61363f2
to
5126b2e
Compare
|
Hmm, interesting. The shifting issue I had before was due to previous use of |
a2133bb
to
62df706
Compare
62df706
to
fd22598
Compare
Fixes issue 11393. The problem is that left and top make no sense for a width by height array; they only make sense in a larger array where from which a smaller part is extracted. Thus, the overall size of the array is provided to CopyRegion in addition to the sub-region. EncodeXFB already handles the extraction, so CopyRegion's only use there is to resize the image (and thus no sub-region is provided).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, sorry about that. LGTM!
Fixes issue 11393 (I haven't actually tested the game, only fifologs).
All of the Rogue Squadron 2 fifologs segfualt (per the buildbot log (lines 309, 1624, 2939, and 4509)), starting in 609a17a (hybrid XFB). This also happens on Windows (where it fails with
Critical error detected c0000374(heap corruption))The problem is that left and top make no sense for a width by height array; they only make sense in a larger array where from which a smaller part is extracted. EncodeXFB already handles the extraction, so CopyRegion's only use is to resize the image. The rects in ScaleTexture have left and top as 0 (from TextureConfig::GetRect as called by TextureCacheBase::ScaleTextureCacheEntryTo), so this changes nothing for them. I'm not entirely sure why
Rectangleis used here at all; aSizeor something like that (which I don't think currently exists) would be better.This is a draft to check for regressions with FifoCI (like #9315).