Skip to content

FIX: validate numeric data for range (upper and lower bound) #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gargsaumya
Copy link
Contributor

@gargsaumya gargsaumya commented Jun 11, 2025

AB#37475
This pull request enhances the BindParameters function in mssql_python/pybind/ddbc_bindings.cpp by introducing range validation for various parameter types to ensure data integrity and prevent out-of-range errors. Below are the key changes grouped by parameter type:

Integer Parameter Validations

  • Signed 16-bit integer (short): Added range validation to ensure the value is within the limits of a signed 16-bit integer. Throws an exception if the value is out of range.
  • Unsigned 16-bit integer (unsigned short): Added validation to check that the value does not exceed the maximum limit of an unsigned 16-bit integer.
  • Signed 64-bit integer (int64_t): Introduced range validation to confirm the value is within the bounds of a signed 64-bit integer.
  • Unsigned 64-bit integer (uint64_t): Added a check to ensure the value does not exceed the maximum limit for an unsigned 64-bit integer.

Date Parameter Validation

  • SQL Server Date Range: Implemented validation for year attributes in date parameters to ensure they fall within the valid SQL Server date range (1753-9999).

Checklist

  • Tests Passed (if applicable) : All pytests passed.

@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 14:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds explicit range checks to the BindParameters function to prevent out-of-range values for integer and date parameters, throwing an exception on invalid input.

  • Casts Python ints to C++ types and enforces min/max bounds for signed/unsigned 16-bit and 64-bit integers.
  • Validates that a Python date’s year falls within SQL Server’s allowed range (1753–9999).
  • Throws std::runtime_error when parameters violate these constraints.
Comments suppressed due to low confidence (2)

mssql_python/pybind/ddbc_bindings.cpp:346

  • [nitpick] You’ve already extracted year into a local variable—reuse it here instead of calling param.attr("year").cast<int>() again for clarity and slight performance improvement.
sqlDatePtr->year = param.attr("year").cast<int>();

mssql_python/pybind/ddbc_bindings.cpp:269

  • Add or update unit tests to cover out-of-range scenarios for each new validation branch (e.g., below std::numeric_limits<short> and above std::numeric_limits<unsigned short>).
// Range validation for signed 16-bit integer

@microsoft microsoft deleted a comment from Copilot AI Jun 11, 2025
@microsoft microsoft deleted a comment from Copilot AI Jun 11, 2025
@gargsaumya gargsaumya requested a review from sumitmsft June 12, 2025 04:11
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.

1 participant