Skip to content

Commit 5734301

Browse files
authored
Fix Coverity static analysis defects (Feb) (openvinotoolkit#3376)
## Description Fix three Coverity static analysis defects across speculative decoding, LLM pipeline, and Whisper components. - **CID 6415047 (INTEGER_OVERFLOW)**: Add boundary guards before decrementing unsigned indices in DTW backtracking to prevent `size_t` underflow - [CVS-181400](https://jira.devtools.intel.com/projects/CVS/issues/CVS-181400) - **CID 6419148 (MISSING_LOCK)**: Access `m_draft_generations_mutex` field directly instead of through accessor in `generate_common` template, so Coverity can correlate the lock with the guarded data - [CVS-181402](https://jira.devtools.intel.com/projects/CVS/issues/CVS-181402) - **CID 6415437 (NULL_FIELD)**: Add defensive assertion on `main_model_descr.model` before passing it to `StatefulLLMPipeline` constructor - [CVS-181401](https://jira.devtools.intel.com/projects/CVS/issues/CVS-181401)
1 parent 1e3fce5 commit 5734301

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/cpp/src/llm/pipeline.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ static std::unique_ptr<LLMPipelineImplBase> create(const std::shared_ptr<ov::Mod
151151

152152
auto main_model_descr =
153153
ov::genai::ModelDesc(model, tokenizer, device, properties_without_draft_model, {}, generation_config);
154+
OPENVINO_ASSERT(main_model_descr.model, "Model descriptor must contain a valid model");
154155

155-
if (draft_model_descr.model != nullptr) {
156+
if (draft_model_descr.model) {
156157
// FIXME: Add support for StatefulSpeculativeLLMPipeline for non-NPU devices for both models.
157158
OPENVINO_ASSERT(device == "NPU" || draft_model_descr.device == "NPU",
158159
"Stateful FastDraft and Stateful Eagle3 Speculative Decoding require NPU to be "

src/cpp/src/speculative_decoding/continuous_batching/fast_draft_strategy.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ std::vector<EncodedGenerationResult> generate_common(
5959

6060
std::vector<GenerationHandle> main_generations;
6161
{
62-
std::lock_guard<std::mutex> lock(self->draft_generations_mutex());
62+
std::lock_guard<std::mutex> lock(self->m_draft_generations_mutex);
6363
for (size_t rid = 0; rid < input_ids.size(); ++rid) {
6464
GenerationConfig main_cfg = sampling_params[rid];
6565
GenerationConfig draft_cfg = main_cfg;
@@ -196,7 +196,6 @@ class ContinuousBatchingPipeline::SpeculativeDecodingImpl : public ContinuousBat
196196
Tokenizer& tokenizer() { return m_tokenizer; }
197197
const Tokenizer& tokenizer() const { return m_tokenizer; }
198198

199-
std::mutex& draft_generations_mutex() { return m_draft_generations_mutex; }
200199
};
201200

202201
} // namespace ov::genai

src/cpp/src/whisper/word_level_timestamps.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,17 @@ std::vector<std::pair<size_t, size_t>> dtw_and_backtrace(const std::vector<std::
269269
path.push_back({path_i, path_j});
270270
int t = trace[i][j];
271271
if (t == 0) {
272-
i--;
273-
j--;
272+
OPENVINO_ASSERT(i > 0 && j > 0, "Invalid DTW trace: diagonal move at matrix boundary");
273+
--i;
274+
--j;
274275
} else if (t == 1) {
275-
i--;
276+
OPENVINO_ASSERT(i > 0, "Invalid DTW trace: up move at top boundary");
277+
--i;
276278
} else if (t == 2) {
277-
j--;
279+
OPENVINO_ASSERT(j > 0, "Invalid DTW trace: left move at left boundary");
280+
--j;
281+
} else {
282+
OPENVINO_THROW("Invalid DTW trace value: ", t);
278283
}
279284
}
280285

0 commit comments

Comments
 (0)