mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 07:17:27 +00:00
Merge pull request #221 from gamedig/fix/read-string-may-panic-index-out-of-range
This commit is contained in:
commit
ada3c548f0
1 changed files with 9 additions and 0 deletions
|
|
@ -145,6 +145,15 @@ impl<'a, B: ByteOrder> Buffer<'a, B> {
|
|||
///
|
||||
/// Returns a `BufferError` if there is an error decoding the string.
|
||||
pub fn read_string<D: StringDecoder>(&mut self, until: Option<D::Delimiter>) -> GDResult<String> {
|
||||
// Check if the cursor is out of bounds.
|
||||
if self.cursor > self.data_length() {
|
||||
return Err(PacketUnderflow.context(format!(
|
||||
"Cursor position {} is out of bounds when reading string. Buffer length: {}",
|
||||
self.cursor,
|
||||
self.data_length()
|
||||
)));
|
||||
}
|
||||
|
||||
// Slice the data array from the current cursor position to the end.
|
||||
let data_slice = &self.data[self.cursor ..];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue