mrichards42 / xword

Cross-platform crossword solving
https://mrichards42.github.io/xword/
GNU General Public License v3.0
42 stars 13 forks source link

Crash when entering a rebus into a square with an empty solution string #185

Open jpd236 opened 2 years ago

jpd236 commented 2 years ago

https://github.com/mrichards42/xword/blob/master/puz/Square.cpp#L491

This line doesn't check if len > 0, so if you enter a rebus into a square with an empty solution, it will crash. Note that this bounds check is present a few lines above in HasTextRebus.

jpd236 commented 2 years ago

Normally, if a puzzle specifies a blank solution, it gets set to ' ', so this missing check isn't typically a problem.

However, if a puzzle's solution is an invalid character according to Square::ToGrid, such as "*", it is possible for it to be set to the '\0' character instead by SetSolutionRebus. If you then try to enter a rebus into that square, it crashes.

(Which raises the point that a puzzle with "*" as the solution cannot be solved in XWord, but does work in AmuseLabs, I guess).

mrichards42 commented 2 years ago

Yeah, we're starting to see some consequences of XWord starting as an AcrossLite clone :/

I suppose adding the bounds check would be a good plan at the very least. I suppose it might make sense to handle invalid strings in SetSolutionRebus and SetPlainSolution by making them Blank?

(Which raises the point that a puzzle with "*" as the solution cannot be solved in XWord, but does work in AmuseLabs, I guess).

This probably isn't a technical limitation since * doesn't have any special meaning, aside from XGridCtrl binding that to "toggle circle" like AL does.

We could probably remove a lot more limitations by having the "is this solution string valid" check consider the string as a whole instead of character-by-character (I think the only truly invalid strings are the black-square string, and a string matching the [{byte}] pattern, but just "[" or "]" could be valid strings).