Skip to content

Validate cuOptGetErrorString buffer size#1313

Open
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/error-string-buffer-size
Open

Validate cuOptGetErrorString buffer size#1313
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/error-string-buffer-size

Conversation

@fallintoplace
Copy link
Copy Markdown

This tightens one C API edge case and adds a small regression test for it.

What changed:

  • reject non-positive buffer sizes in cuOptGetErrorString
  • add a focused C API test that checks 0 and -1 buffer sizes

Why:
cuOptGetParameter already rejects <= 0 output buffer sizes, but cuOptGetErrorString was still passing its signed size straight into snprintf. This just makes the behavior consistent and keeps the validation on the API boundary.

Testing:

  • git diff --check
  • not run here: this machine does not have nvcc or a configured cuOpt build environment, so I could not build libcuopt / run C_API_TEST locally

Closes #1311.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 27, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@fallintoplace fallintoplace marked this pull request as ready for review May 27, 2026 22:00
@fallintoplace fallintoplace requested a review from a team as a code owner May 27, 2026 22:00
@fallintoplace fallintoplace requested review from hlinsen and rg20 May 27, 2026 22:00
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e27073a9-2a54-48bf-997d-e90db1bd1e0b

📥 Commits

Reviewing files that changed from the base of the PR and between d415bb6 and bd69111.

📒 Files selected for processing (4)
  • cpp/src/pdlp/cuopt_c.cpp
  • cpp/tests/linear_programming/c_api_tests/c_api_test.c
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp
  • cpp/tests/linear_programming/c_api_tests/c_api_tests.h

📝 Walkthrough

Walkthrough

This PR adds input validation to the cuOptGetErrorString C API function to reject non-positive buffer sizes. The implementation guard returns CUOPT_INVALID_ARGUMENT when error_string_size <= 0, matching the existing validation pattern in cuOptGetParameter. A new test creates an optimization problem, solves it, and verifies the function correctly rejects zero and negative buffer sizes before cleanup.

Changes

Error String Buffer Size Validation

Layer / File(s) Summary
Implementation: buffer size validation in cuOptGetErrorString
cpp/src/pdlp/cuopt_c.cpp
Added early return guard in cuOptGetErrorString to reject error_string_size <= 0 before passing to std::snprintf, returning CUOPT_INVALID_ARGUMENT.
Test coverage for invalid buffer sizes
cpp/tests/linear_programming/c_api_tests/c_api_tests.h, cpp/tests/linear_programming/c_api_tests/c_api_test.c, cpp/tests/linear_programming/c_api_tests/c_api_tests.cpp
Added test function declaration, C test implementation that constructs a problem, calls the API with zero and negative buffer sizes, verifies rejection, and GoogleTest wrapper to integrate with the test suite.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Validate cuOptGetErrorString buffer size' clearly and concisely describes the main change: adding validation for buffer size in the cuOptGetErrorString function.
Description check ✅ Passed The description explains the change (rejecting non-positive buffer sizes), the reasoning (consistency with cuOptGetParameter), and notes testing limitations, all directly related to the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #1311 by implementing the validation check in cuOptGetErrorString and adding a regression test for buffer sizes 0 and -1.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue requirements: validation in cuOptGetErrorString and tests for the new behavior. No out-of-scope changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] cuOptGetErrorString should reject non-positive buffer sizes

1 participant