Commit 76a5397
authored
fix: assorted arithmetic and indexing robustness fixes (#2451)
* fix(core): avoid i64 underflow on expired GCP token
When a cached GCP access token was already expired (expires_at_ms < now),
the remaining lifetime calculation used plain subtraction:
(expires_at_ms - now) / 1000. This underflows in debug builds and wraps
in release builds.
Use saturating_sub so an expired token simply yields a non-positive
remaining lifetime and is skipped. Add a regression test.
Signed-off-by: Andrew White <andrewh@cdw.com>
* fix(server): avoid i64 underflow in lease age calculation
The lease steal path computed age as now_ms() - record.updated_at_ms.
If the stored updated_at timestamp is in the future (e.g. clock skew),
the subtraction underflows. Use saturating_sub to treat a future
timestamp as age 0, keeping the lease considered fresh.
Signed-off-by: Andrew White <andrewh@cdw.com>
* fix(server): avoid i64 overflow on large credential max lifetime
max_lifetime_seconds is only validated as >= 0. The code multiplied the
raw i64 value by 1000 to compute max_expires, which overflows for
values above i64::MAX / 1000. The capped i32 value used for the STS
request was already computed but not reused.
Compute max_lifetime_ms from the capped value with saturating_mul and
use it for both expires_at fallback and max_expires.
Signed-off-by: Andrew White <andrewh@cdw.com>
* fix(server): avoid hardcoded indexing into base_url_config_keys
resolve_vertex_ai_route assumed every inference provider profile has at
least two base URL config keys by indexing [0] and [1]. Only the Vertex
profile satisfies that today; other profiles would panic here.
Iterate base_url_config_keys with find_map instead, and add a test with
an empty key list to ensure no panic.
Signed-off-by: Andrew White <andrewh@cdw.com>
* fix(server): clamp lease age at zero for future timestamps
Address review feedback: add regression coverage for future-timestamp
lease clock skew. Extract lease_is_expired() and clamp the age at zero —
i64::saturating_sub saturates at i64::MIN, not zero, so a future
updated_at_ms must be clamped explicitly to be treated as age zero and
remain unstealable with a positive TTL.
Signed-off-by: Andrew White <andrewh@cdw.com>
* fix(server): fall back past blank preferred Vertex base URL
Address review feedback: find_map stopped at the first present key even
when its value was blank, and the outer filter discarded it without
considering lower-priority aliases. Filter blank values inside the
closure so a blank preferred key falls back to a valid alias, matching
the documented priority order. Add a regression test with a blank
preferred key and a valid fallback.
Signed-off-by: Andrew White <andrewh@cdw.com>
* fix(server): saturate AWS STS expiry cap on saturated clock
Address review feedback: now_ms + max_lifetime_ms could still overflow
when current_time_ms() saturates near i64::MAX. Compute
max_expires = now_ms.saturating_add(max_lifetime_ms) once and use it for
both the conversion fallback and the expiry cap. Add a boundary unit
test covering a saturated clock.
Signed-off-by: Andrew White <andrewh@cdw.com>
---------
Signed-off-by: Andrew White <andrewh@cdw.com>1 parent 516be60 commit 76a5397
4 files changed
Lines changed: 133 additions & 12 deletions
File tree
- crates
- openshell-core/src
- openshell-server/src
- compute
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
590 | 611 | | |
591 | 612 | | |
592 | 613 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
255 | 266 | | |
256 | 267 | | |
257 | 268 | | |
| |||
351 | 362 | | |
352 | 363 | | |
353 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
354 | 387 | | |
355 | 388 | | |
356 | 389 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
630 | | - | |
631 | | - | |
632 | | - | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
633 | 634 | | |
634 | | - | |
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| |||
1133 | 1133 | | |
1134 | 1134 | | |
1135 | 1135 | | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
1136 | 1195 | | |
1137 | 1196 | | |
1138 | 1197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
769 | 769 | | |
770 | 770 | | |
771 | 771 | | |
| 772 | + | |
772 | 773 | | |
773 | 774 | | |
774 | 775 | | |
| |||
794 | 795 | | |
795 | 796 | | |
796 | 797 | | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
| 798 | + | |
| 799 | + | |
802 | 800 | | |
803 | 801 | | |
804 | 802 | | |
| |||
1519 | 1517 | | |
1520 | 1518 | | |
1521 | 1519 | | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
1522 | 1530 | | |
1523 | 1531 | | |
1524 | 1532 | | |
| |||
0 commit comments