fix Bitmap's object to string conversion #62
No reviewers
Labels
No Label
RGSS accuracy
bug
compilation
discussion
documentation
duplicate
enhancement
invalid
performance issue
port request
question
ruby incompatibility
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: MapleShrine/mkxp#62
Loading…
Reference in New Issue
No description provided.
Delete Branch "mri-bitmap-fix-obj2str-conversion"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Calling #to_s might not return a string (it should though).
The RGSS also calls
rb_obj_as_string
:Don't worry about tainting, I just wanted to prove it (for some reason). More importantly is that RGSS classes don't check if the string contains
'\0'
. For example, drawing"Te\0st"
doesn't raise an error like it should (see “poison null byte”) and only drawsTe
. Should mkxp?If RGSS behaves this way (ie. treating it as a null terminated C string regardless of the actual length), then I don't see a problem with mkxp too continuing to behave like this. Are there any corner cases you're aware of where this might end up hurting?
I don't think so. But using
StringValueCStr
(which makes sure that a string doesn't contain NUL) instead ofRSTRING_PTR
would probably ease your concerns about CRuby's GC.I didn't mention that
Bitmap.new
with a filename is affected, too. I doubt fixing this bug would break a game. Of course, the RGSS isn't as important as a libc or CRuby itself.I don't understand how they are related in this case. A rogue null inside a string just means that we potentially read less than there is to read. How would this affect the GC / libc?
Using
StringValueCStr
would solve both issues, wouldn't it?str
is on the stack and the bug is fixed.Okay, as I've said it's not that important as someone exploiting
Bitmap.new
is unlikely, but I just don't see a major downside in making sure a string, which will be passed to a function that expects null-terminated strings, doesn't contain NULOh, so you mean using this function instead of your
objAsStringPtr
then? Anyway, that's okay, if it makes the code a bit simpler I don't really mind the difference in behavior between RMVX/A and mkxp as it's unlikely to come up. I just don't want to have more code for error checking which RGSS never does in the first place.This actually sounds interesting. How would someone exploit Bitmap.new? The only exploit I've ever heard of was eg. ruby looking at a string with a rogue null, deciding it is "safe" and pass it to a C function, whereas with the null interpreted as the string end, it would no longer be safe. In RGSS, ruby never does anything or looks at the string arguments, they're passed straight to the C++ core.
Anyway, I'll just pull this first as the patch itself is fine. Thanks for your work!