-
Notifications
You must be signed in to change notification settings - Fork 39
Fix: Math:gen_rngのseedにnumを与え、options.algorithmにchacha20を指定した或いは何も指定しなかった場合、seed & 255を内部的にseedとしてしまう問題を修正。
#1019
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
base: master
Are you sure you want to change the base?
Conversation
…eed values. * Added `chacha20NumberSeedLegacyBehaviour` to restore the legacy behaviour (`false` by default)
|
Codecov Report❌ Patch coverage is
... and 29 files with indirect coverage changes 🚀 New features to boost your workflow:
|
| - 関数`Math:gen_rng`の`options.chacha20NumberSeedLegacyBehaviour`に`true`を指定した場合、修正前の動作をする機能を追加(デフォルト:`false`)。 | ||
| - これらの修正により、同じ`seed`でも修正前と修正後で生成される値が異なるようになります。 |
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.
CHANGELOGは基本的にインデントにタブ文字を使っているので一応変更を提案しておきます
| - 関数`Math:gen_rng`の`options.chacha20NumberSeedLegacyBehaviour`に`true`を指定した場合、修正前の動作をする機能を追加(デフォルト:`false`)。 | |
| - これらの修正により、同じ`seed`でも修正前と修正後で生成される値が異なるようになります。 | |
| - 関数`Math:gen_rng`の`options.chacha20NumberSeedLegacyBehaviour`に`true`を指定した場合、修正前の動作をする機能を追加(デフォルト:`false`)。 | |
| - これらの修正により、同じ`seed`でも修正前と修正後で生成される値が異なるようになります。 |
| actualSeed = new Uint8Array(await crypto.subtle.digest('SHA-384', new Uint8Array(new Float64Array([seed.value])))); | ||
| if (seed.type === 'num') { | ||
| const float64Array = new Float64Array([seed.value]); | ||
| const numberAsIntegerOptionValue = options?.get('chacha20NumberSeedLegacyBehaviour'); |
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.
多くのプログラミング言語の標準ライブラリで米式スペルを用いているのを見るのでBehaviorの方がいいかもしれません。
それと、AiScriptでは組み込みプロパティなどにスネークケースを使っているのでそれに合わせたほうが統一感がありそうです。
| const numberAsIntegerOptionValue = options?.get('chacha20NumberSeedLegacyBehaviour'); | |
| const numberAsIntegerOptionValue = options?.get('chacha20_number_seed_legacy_behavior'); |
What
#731 を実装した際、Float64ArrayをUint8Array() constructorの第一引数に指定した場合の仕様の理解が間違っており、
numで与えられたシード値が意図せず& 255されてしまっていました。本修正では、
TypedArray.prototype.bufferを取る事により、#731 の実装時に意図したように、numberの内部表現をそのままseedとして使用することにより、3.0と3.0000000000000004で異なる出力を得られるようになります。これにより、全く同じ
seedでも、修正前と修正後で出力が変わります。また、本修正後も旧来の動作を再現できるよう、関数
Math:gen_rngのoptions.chacha20NumberSeedLegacyBehaviour(デフォルト:false)にtrueを指定した場合、修正前の動作をする機能を追加しました。Before:
After:
Why
某Playの出力が複数日連続で同一となった事により発覚。
algorithmにrc4を指定した場合と挙動が大きく異なるため。Additional info (optional)
Workaround for versions before this fix
seedを与える前に.to_str()等でstringに変換する