Skip to content
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

[ads] General code health #27587

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

[ads] General code health #27587

wants to merge 1 commit into from

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Feb 8, 2025

Resolves brave/brave-browser#43838

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@tmancey tmancey self-assigned this Feb 8, 2025
@tmancey tmancey requested a review from a team as a code owner February 8, 2025 20:12
@tmancey tmancey requested review from aseren and removed request for aseren February 8, 2025 20:13
@tmancey tmancey marked this pull request as draft February 8, 2025 20:14
// Invalid pref path key, because this should be an integer index for the
// list.
return std::nullopt;
}

const base::Value::List& list = pref_value.GetList();

if (index < 0 || index >= static_cast<int>(list.size())) {
if (index < 0 || index >= list.size()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

reported by reviewdog 🐶
[semgrep] Checking if an unsigned variable is negative makes no sense and is usually a good indication that something is probably wrong with the code.

Source: https://github.com/0xdea/semgrep-rules/blob/main/c/incorrect-unsigned-comparison.yaml


Cc @thypon @kdenhartog

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@tmancey tmancey force-pushed the issues/43838 branch 3 times, most recently from 8c7ccfc to 963d499 Compare February 11, 2025 15:53
@tmancey tmancey marked this pull request as ready for review February 11, 2025 15:54
Copy link
Contributor

[puLL-Merge] - brave/brave-core@27587

Here's my review of the changes:

Description

This PR refactors integer types in Brave Ads code to use size_t instead of int for container sizes and array indices. This is a good practice since sizes and indices are always non-negative, and size_t is the proper type for array indexing and size operations. The PR also contains some cleanup of challenge bypass ristretto test utilities and constants.

Changes

Changes

By filename:

  1. account/ad_events/ad_event_test_util.*:
  • Changed int parameters to size_t for count-related functions
  • Updated tests to use size_t literals with 'U' suffix
  1. account/confirmation_tokens/confirmation_tokens_test_util.*:
  • Switched to size_t for token counts
  • Added random token generation capability
  • Updated test constants with new deterministic test values
  1. account/issuers/*:
  • Refactored maximum token issuer public keys parameter to use size_t
  • Updated related tests to compare against size_t values
  1. account/tokens/*:
  • Modernized token utilities to use size_t for sizes and counts
  • Added proper type declarations for token lists
  • Improved test data organization
  1. Various feature files:
  • Changed int parameters to size_t for:
    • Maximum ads per hour/day
    • Token counts
    • Queue sizes
    • History limits
    • Page visit caps
sequenceDiagram
    participant Client
    participant TokenGenerator
    participant BatchDLEQProof
    participant TokenIssuer
    
    Client->>TokenGenerator: Request token generation (size_t count)
    TokenGenerator-->>Client: Return raw tokens
    Client->>TokenIssuer: Request token signing
    TokenIssuer->>BatchDLEQProof: Generate proof
    BatchDLEQProof-->>Client: Return signed tokens
    Client->>Client: Store tokens (size_t max)
Loading

Security Hotspots

  1. Token Verification: The change in verification signatures and blinded tokens requires careful verification that token validation still works correctly to prevent token forgery.

  2. Array Bounds: The change from int to size_t for array indices needs careful testing to avoid potential integer overflow issues in boundary conditions.

Let me know if you would like me to elaborate on any part of the review.

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.

[ads] General code health
3 participants