Equim-chan / Mortal

🚀🀄️ A fast and strong AI for riichi mahjong, powered by Rust and deep reinforcement learning.
https://mortal.ekyu.moe
GNU Affero General Public License v3.0
929 stars 118 forks source link

Potential overflow #22

Closed A0nameless0man closed 1 year ago

A0nameless0man commented 1 year ago

This line reserves 4 ArrayVec with capacity of 24 to record kawa.

https://github.com/Equim-chan/Mortal/blob/c357889efffeeaa787d926358c71412ea5ecf77d/libriichi/src/state/player_state.rs#L75

Which isn't adequate because this lines can push at most 8 None into it .

https://github.com/Equim-chan/Mortal/blob/c357889efffeeaa787d926358c71412ea5ecf77d/libriichi/src/state/update.rs#L692-L699

In my test , program sometimes crash at this line.

https://github.com/Equim-chan/Mortal/blob/c357889efffeeaa787d926358c71412ea5ecf77d/libriichi/src/state/update.rs#L233

Equim-chan commented 1 year ago

This has been fixed in v2 but not yet ported to v1 (this repo). The fix simply goes by changing ArrayVec to TinyVec.