8000
Skip to content

Fix length checks for name and data in htsmsg_binary#2076

Open
Flole998 wants to merge 1 commit intomasterfrom
Flole998-patch-8
Open

Fix length checks for name and data in htsmsg_binary#2076
Flole998 wants to merge 1 commit intomasterfrom
Flole998-patch-8

Conversation

@Flole998
Copy link
Copy Markdown
Member
@Flole998 Flole998 commented Mar 3, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 3, 2026 13:43
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of th 8000 e htsmsg_binary_des0 function by implementing more rigorous length validations and preventing potential integer overflows during the deserialization of binary messages. These changes collectively improve the security and stability of the message parsing logic, particularly when handling malformed or unexpectedly large input data.

Highlights

  • Improved Length Validation: The initial length check if(len < namelen + datalen) has been refined to if (namelen > len || datalen > len - namelen) to more accurately prevent buffer over-reads by ensuring namelen and datalen do not exceed the available len.
  • Integer Overflow Prevention: A new check if (datalen > SIZE_MAX - tlen - 1) was introduced for HMF_STR types to prevent potential integer overflow when calculating tlen (total length) before memory allocation.
  • Corrected UUID Size Calculation: The tlen calculation for HMF_UUID types was corrected from tlen = UUID_BIN_SIZE to tlen += UUID_BIN_SIZE, ensuring that the size of the field structure is also accounted for. Additionally, the datalen is now explicitly checked to match UUID_BIN_SIZE.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/htsmsg_binary.c
    • Updated length validation logic for namelen and datalen to prevent buffer over-reads.
    • Added an integer overflow check for datalen when processing HMF_STR types.
    • Corrected the tlen calculation and added a datalen validation for HMF_UUID types.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonarqubecloud
Copy link
Copy Markdown
sonarqubecloud bot commented Mar 3, 2026

Copy link
Copy Markdown
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes several potential security vulnerabilities in htsmsg_binary_des0, including integer overflows and a heap buffer overflow. The checks for namelen and datalen against the buffer length are improved to prevent overflow. An overflow check is added for string field length calculation. The total length calculation for UUID fields is corrected, fixing a critical buffer overflow vulnerability. My review includes one suggestion to further improve robustness by adding a missing overflow check for consistency.

} else if (type == HMF_UUID) {
tlen = UUID_BIN_SIZE;
if (tlen != datalen)
tlen += UUID_BIN_SIZE;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency with the integer overflow check added for HMF_STR, it would be good practice to also add a check here to prevent tlen from overflowing before adding UUID_BIN_SIZE. While an overflow is unlikely given UUID_BIN_SIZE is a small constant, adding the check improves robustness and consistency.

You could add a check like this before the addition:

if (tlen > SIZE_MAX - UUID_BIN_SIZE) {
  return -1;
}

Copy link
Copy Markdown
Contributor
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

Adjusts htsmsg_binary deserialization length and allocation calculations to prevent incorrect bounds checks and ensure proper sizing for specific field types (notably UUID and strings).

Changes:

  • Reworks name/data remaining-length validation to avoid overflow-prone namelen + datalen checks.
  • Adds an allocation overflow guard for string fields before computing tlen += datalen + 1.
  • Fixes UUID allocation sizing by adding UUID_BIN_SIZE to the existing field allocation size (instead of overwriting it).

Comment on lines 59 to +61
if (type == HMF_STR) {
if (datalen > SIZE_MAX - tlen - 1)
return -1;
Copy link
Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

Line 60 introduces a tab/misaligned indentation inside the if (type == HMF_STR) block, which breaks the surrounding indentation style and can cause noisy diffs in future edits. Please re-indent this block consistently (spaces only, aligned with the other statements in the function).

Copilot uses AI. Check for mistakes.
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.

2 participants

0