Skip to content

Commit f3da97e

Browse files
committed
kv-cache : bounds-check when accessing slot_info indices
1 parent a70293b commit f3da97e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/llama-kv-cache-unified.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ void llama_kv_cache_unified::apply_ubatch(const slot_info & sinfo, const llama_u
717717
assert(ubatch.n_tokens == sinfo.idxs.size());
718718

719719
for (uint32_t i = 0; i < ubatch.n_tokens; ++i) {
720-
const auto idx = sinfo.idxs[i];
720+
const auto idx = sinfo.idxs.at(i);
721721

722722
if (!cells.is_empty(idx)) {
723723
assert(cells.seq_count(idx) == 1);
@@ -915,7 +915,7 @@ void llama_kv_cache_unified::set_input_k_idxs(ggml_tensor * dst, const llama_uba
915915
int64_t * data = (int64_t *) dst->data;
916916

917917
for (int64_t i = 0; i < n_tokens; ++i) {
918-
data[i] = sinfo.idxs[i];
918+
data[i] = sinfo.idxs.at(i);
919919
}
920920
}
921921

@@ -930,7 +930,7 @@ void llama_kv_cache_unified::set_input_v_idxs(ggml_tensor * dst, const llama_uba
930930
int64_t * data = (int64_t *) dst->data;
931931

932932
for (int64_t i = 0; i < n_tokens; ++i) {
933-
data[i] = sinfo.idxs[i];
933+
data[i] = sinfo.idxs.at(i);
934934
}
935935
}
936936

src/llama-kv-cache-unified.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class llama_kv_cache_unified : public llama_memory_i {
4242
idx_vec_t idxs;
4343

4444
uint32_t head() const {
45-
return idxs[0];
45+
return idxs.at(0);
4646
}
4747

4848
bool empty() const {

0 commit comments

Comments
 (0)