NNUE: Bound network description size - #6904
Conversation
|
(execution 27439275413 / attempt 1) |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis change adds description size validation to the NNUE network I/O layer. A new internal constant Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I don't think this is an issue that needs to be fixed. The file is supposed to be sane and worst case the kernel will throw us out for OOM reasons. EDIT: just wondering, I see you guarding for size 0. Do we currently bail out cleanly in that case, in master? |
|
I don't think we need to be sanitizing network data Could be a fun CTF pwn challenge ;) |
|
I agree this is not an issue for valid/sane network files, and I’m not trying to argue that normal network data needs heavy validation. The reason I thought this was worth guarding is narrower: the value comes from serialized file metadata and is used as an allocation size before the loader has any chance to reject the file. So a corrupt header can make the process attempt an arbitrary-sized I agree the worst case is “just” process termination / OOM rather than memory corruption, but avoiding an avoidable OOM path seems like a reasonable cheap check at the file boundary. The limit is intentionally far above any realistic description size, so it should not affect valid networks. On the size-0 question: I don’t think master bails out for size 0. It resizes the string to 0 and then calls If the project preference is that NNUE files are assumed sane and we intentionally avoid even small validation checks here, I’m fine closing this PR. |
Limits the NNUE network description length accepted from the file header before resizing the description string.
The description size is stored in the NNUE header and read from the network file. Previously, this value was used directly to resize the description string, so a malformed file could request an excessively large allocation before the loader failed.
This patch adds a conservative upper bound for the description field and applies the same bound when writing network headers.
Verification:
make -j buildpassed.