[c++] Add bounds check in StringToArrayFast() to prevent heap buffer over-read#6998
[c++] Add bounds check in StringToArrayFast() to prevent heap buffer over-read#6998sanjay20m wants to merge 4 commits intolightgbm-org:masterfrom
Conversation
…ffer over-read This patch fixes a heap buffer over-read vulnerability in the C++ core of LightGBM. The `StringToArrayFast()` function did not check if the parser had reached the end of the string before reading the next array element.
jameslamb
left a comment
There was a problem hiding this comment.
Thanks for your interest in LightGBM.
How did you discover this? How can we test it? Can you share a normal model file and one modified in the way you say this protects against, so we can understand what's being proposed here?
|
Hi @jameslamb How to reproduce
This demonstrates that the change prevents a possible heap buffer over-read when loading malformed model files. |
|
Hello @jameslamb , Can u take some time to review! |
Summary
This PR fixes a memory safety issue in
StringToArrayFast()where the parsercould read past the end of the model string when the declared array size was
larger than the available data.
Vulnerability
An attacker could create a malicious LightGBM text model file with:
This mismatch would cause the parser to read beyond the allocated buffer,
triggering undefined behavior. This can result in:
Fix
Security Impact
This hardens the model loading path against malicious or corrupted model files.
The patch does not change public APIs or intended parsing behavior.