Skip to content

Fix CodeQL alerts: size_t index math in the Laya scorer, read-only token for ci - #152

Merged
bong-water-water-bong merged 1 commit into
mainfrom
fix/codeql-alerts
Sep 26, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
fix/codeql-alerts

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes the three open code-scanning alerts.

  • Alerts 2 and 3 (cpp/integer-multiplication-cast-to-long, laya/scorer.cpp): the collate and key-padding loops computed i * L + j in int before indexing. Each index is now widened to size_t before the multiply, as the rest of the file already does. With current inputs these can't overflow; the change makes the math match the vectors' size_t sizes.
  • Alert 1 (actions/missing-workflow-permissions, ci.yml): the workflow now declares permissions: contents: read, like every other workflow in the repo.

laya/scorer.cpp compiles cleanly (g++ -std=c++20 -fsyntax-only).

🤖 Generated with Claude Code

…ken for ci

cpp/integer-multiplication-cast-to-long (alerts 2, 3): the collate and
padding loops in laya/scorer.cpp indexed with int * int before widening;
widen first, as the rest of the file does.
actions/missing-workflow-permissions (alert 1): ci.yml now declares
contents: read like every other workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@context7

context7 Bot commented Sep 26, 2026

Copy link
Copy Markdown

Docs7 for 1bit-monster/engine

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit 2cdbd09

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Integer Overflow Risk

The fix addresses potential integer overflow in index calculations by ensuring that indices are widened to size_t before multiplication. This change aligns the code with the rest of the file's usage of size_t for vector indexing, preventing possible undefined behavior when dealing with large inputs.

if (key_pad[(size_t)b * L + j]) { sr[j] = -INFINITY; continue; }
Consistent Indexing Types

The code now consistently uses size_t for indexing in the collate and key-padding loops, matching the vector sizes and preventing type mismatch issues that could lead to incorrect memory access or overflow.

for (size_t j = 0; j < seqs[i].size(); ++j) { input_ids[(size_t)i * L + j] = seqs[i][j]; attn[(size_t)i * L + j] = 1; }
for (size_t j = 0; j < markers[i].size(); ++j) { mpos[(size_t)i * K + j] = markers[i][j]; mmask[(size_t)i * K + j] = 1; }
Memory Access Alignment

The change ensures that memory access patterns in the memcpy call use size_t for indexing, which is consistent with the vector sizes and prevents potential issues with signed/unsigned integer comparisons or overflow in memory addressing.

memcpy(h.data() + ((size_t)b * L + t) * D, tok_emb_.data() + (size_t)input_ids[(size_t)b * L + t] * D, D * 4);

@bong-water-water-bong
bong-water-water-bong merged commit f346e69 into main Sep 26, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/codeql-alerts branch September 26, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant