Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
6deeecb1
Unverified
Commit
6deeecb1
authored
Oct 25, 2025
by
ryan-lempka
Committed by
GitHub
Oct 25, 2025
Browse files
fix: char boundary panic jail (#3893)
parent
48b622c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
5 deletions
+25
-5
lib/llm/src/backend.rs
lib/llm/src/backend.rs
+25
-5
No files found.
lib/llm/src/backend.rs
View file @
6deeecb1
...
...
@@ -457,11 +457,7 @@ impl Decoder {
}
}
if
self
.jail
.len
()
>
self
.jail_max_bytes
{
// truncate the jail
let
drain_len
=
self
.jail
.len
()
-
self
.jail_max_bytes
;
self
.jail
.drain
(
0
..
drain_len
);
}
Self
::
maybe_drain_to_max_bytes
(
&
mut
self
.jail
,
self
.jail_max_bytes
);
}
Ok
(
StepResult
::
ok
(
token
))
...
...
@@ -530,4 +526,28 @@ impl Decoder {
None
}
}
fn
maybe_drain_to_max_bytes
(
s
:
&
mut
String
,
max_bytes
:
usize
)
{
if
s
.len
()
>
max_bytes
{
let
mut
drain_len
=
s
.len
()
-
max_bytes
;
while
!
s
.is_char_boundary
(
drain_len
)
{
drain_len
-=
1
;
}
s
.drain
(
0
..
drain_len
);
}
}
}
mod
tests
{
#[test]
fn
test_char_boundary_drain
()
{
use
super
::
Decoder
;
let
mut
s
=
String
::
from
(
"helloñworld"
);
// 12 bytes total ñ is 2 bytes
let
max_bytes
=
6
;
// 12 - 6 = 6 which is inside ñ
assert
!
(
!
s
.is_char_boundary
(
s
.len
()
-
max_bytes
));
// initially we are not on a char boundary
Decoder
::
maybe_drain_to_max_bytes
(
&
mut
s
,
max_bytes
);
assert
!
(
s
.is_char_boundary
(
0
));
// front of jail string on valid char boundary
assert_eq!
(
s
,
"ñworld"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment