Skip to content

Conversation

@swesterfeld
Copy link
Collaborator

This makes sense since Random::seed only uses 8 bits from the stream enum anyway (and having more bits for stream numbers wouldn't make it "more secure").

This makes sense since Random::seed only uses 8 bits from the stream enum
anyway (and having more bits for stream numbers wouldn't make it "more
secure").

Signed-off-by: Stefan Westerfeld <[email protected]>
Copy link

@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.

Summary of Changes

Hello @swesterfeld, 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 introduces a targeted optimization to the Random::Stream enum definition within cxx/random.hh. The primary goal is to reduce the memory footprint and improve the clarity of the enum by aligning its underlying data type and member values with its actual usage requirements.

Highlights

  • Enum Type Optimization: The underlying type of the Random::Stream enum in cxx/random.hh has been changed from uint32_t to uint8_t. This change is made because the Random::seed function only utilizes 8 bits from the stream enum, making a 32-bit type unnecessarily large and not contributing to security.
  • Enum Value Simplification: The hexadecimal values assigned to the Random::Stream enum members (wm_pattern, wm_mask, wm_convcode, img_comment) have been replaced with simple, sequential integer values (1, 2, 3, 4). This improves readability and aligns with the new uint8_t underlying type.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.

Copy link

@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

The pull request correctly identifies that the Random::Stream enum only requires 8 bits and changes its underlying type from uint32_t to uint8_t. However, the new enum values introduce a critical breaking change, as they will alter the generated random streams, making existing watermarks unreadable. My review includes a suggestion to preserve the original behavior by using the lower 8 bits of the old enum values, thus making the change safe and backward-compatible.

Comment on lines +31 to +34
wm_pattern = 1,
wm_mask = 2,
wm_convcode = 3,
img_comment = 4,

Choose a reason for hiding this comment

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

critical

Changing the enum values will alter the generated pseudo-random sequences. This is a critical breaking change that will prevent watermarks created with older versions of this tool from being read correctly.

The Random::seed function was already using only the lower 8 bits of the Stream enum value by casting it to uint8_t.

To maintain backward compatibility, I suggest using the lower 8 bits of the original uint32_t values.

The original values and their lower 8 bits are:

  • wm_pattern: 0xe58eb537 -> 0x37
  • wm_mask: 0xfd19fc82 -> 0x82
  • wm_convcode: 0x7ecf1f7a -> 0x7a
  • img_comment: 0x7abcde01 -> 0x01

These are all unique and would preserve the behavior of the random number generator, making this change non-breaking.

    wm_pattern  = 0x37,
    wm_mask     = 0x82,
    wm_convcode = 0x7a,
    img_comment = 0x01,

@tim-janik
Copy link
Owner

Thank you.
Please add a note about BREAKING changes to the NEWS file next time.
Merged with #4c2defee557857fb119fab5db05a277867703cac

@tim-janik tim-janik closed this Jul 22, 2025
@swesterfeld swesterfeld deleted the fix-random-stream-enum branch September 29, 2025 15:37
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