Skip to content

fix(bbb-web): Prevent SVGs From Being Generated With Zero Value Dimensions - #24872

Merged
antobinary merged 2 commits into
bigbluebutton:v3.0.x-developfrom
paultrudel:svg-zero-dim-fix
Apr 10, 2026
Merged

antobinary merged 2 commits into
bigbluebutton:v3.0.x-developfrom
paultrudel:svg-zero-dim-fix

Conversation

@paultrudel

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes the SVG generation logic in BBB to prevent dimension identification or resizing failures from allowing generated SVGs to have zero values for their width and/or height. Adds additional logging to notify when SVG dimensions have been returned as zero.

Motivation

Some failures in SVG dimension identification or resizing may result in a generated SVG having zero values for its width and/or height. These zero value dimensions can then cause issues with some Postgres queries and lead to poor performance in the client.

@coderabbitai

coderabbitai Bot commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Updated SVG/image dimension handling and related scaling logic across multiple components. Added warning logs when image width or height cannot be determined and methods return 0. Svg embedding logic now uses configurable MAX_SVG_WIDTH / MAX_SVG_HEIGHT defaults and only overwrites them when both detected dimensions are non-zero, emitting a warning otherwise. SVG parsing was tightened to accept dimensions only when both width and height are > 0. SQL view expressions were changed to use NULLIF(...) to avoid division-by-zero in scaled dimension calculations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: preventing SVGs from having zero-value dimensions, which matches the core objective of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining what the PR fixes (zero-value SVG dimensions), the motivation (preventing issues with Postgres queries), and mentions added logging.

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

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/SvgImageCreatorImp.java (1)

323-329: Solid defensive check with a minor edge-case consideration.

The conditional update and warning log correctly prevents zero dimensions from being written to the SVG. However, there's a subtle edge case: if the initial resolution was larger than MAX (e.g., 2000×1500), then resize occurs but post-resize identification fails, the code keeps the pre-resize dimensions. This could create a mismatch between the SVG viewport size and the actual embedded PNG size.

Consider using MAX dimensions as the fallback after resize failure to ensure consistency:

🔧 Optional: Use MAX dimensions as post-resize fallback
                             if (imageResolution.getWidth() != 0 && imageResolution.getHeight() != 0) {
                                 width = imageResolution.getWidth();
                                 height = imageResolution.getHeight();
                             } else {
+                                width = MAX_SVG_WIDTH;
+                                height = MAX_SVG_HEIGHT;
                                 log.warn("Image resolution after resize returned 0 for page {} of {}, using defaults {}x{}",
                                          page, pres.getName(), width, height);
                             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/SvgImageCreatorImp.java`
around lines 323 - 329, The current check keeps pre-resize width/height when
imageResolution returns 0, which can leave SVG viewport larger than the actual
embedded PNG; update the fallback so when imageResolution.getWidth() or
getHeight() is 0 AND the original dimensions exceeded the configured max, set
width/height to the MAX constants (e.g., MAX_WIDTH, MAX_HEIGHT) used for
resizing instead of retaining pre-resize values; modify the block that checks
imageResolution (symbols: imageResolution, width, height) to choose MAX_* as the
fallback when a resize was expected, and keep the existing log.warn but indicate
that MAX dimensions are being used as the fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/SvgImageCreatorImp.java`:
- Around line 323-329: The current check keeps pre-resize width/height when
imageResolution returns 0, which can leave SVG viewport larger than the actual
embedded PNG; update the fallback so when imageResolution.getWidth() or
getHeight() is 0 AND the original dimensions exceeded the configured max, set
width/height to the MAX constants (e.g., MAX_WIDTH, MAX_HEIGHT) used for
resizing instead of retaining pre-resize values; modify the block that checks
imageResolution (symbols: imageResolution, width, height) to choose MAX_* as the
fallback when a resize was expected, and keep the existing log.warn but indicate
that MAX dimensions are being used as the fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3cd3823f-85f7-4b21-9674-87e89addc194

📥 Commits

Reviewing files that changed from the base of the PR and between 802c084 and 56ac1b8.

📒 Files selected for processing (3)
  • bbb-common-web/src/main/java/org/bigbluebutton/presentation/handlers/ImageResolutionServiceHandler.java
  • bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/SvgImageCreatorImp.java
  • bbb-common-web/src/main/scala/org/bigbluebutton/api2/MsgBuilder.scala

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 hardens SVG dimension handling in the BigBlueButton web/presentation pipeline so that failures in probing image/SVG sizes don’t result in generated SVGs with width="0" and/or height="0" (which can cascade into downstream client/DB performance issues).

Changes:

  • Treat width<=0 / height<=0 as invalid when probing SVG dimensions, forcing a fallback to defaults/other resolution strategies.
  • Use MAX_SVG_WIDTH/MAX_SVG_HEIGHT as non-zero defaults when generating SVGs from embedded PNGs, and avoid overwriting dimensions with zero after a resize pass.
  • Add warning logs when image dimension detection fails and returns 0.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
bbb-common-web/src/main/scala/org/bigbluebutton/api2/MsgBuilder.scala Prevents accepting zero/invalid probed SVG dimensions so page sizing falls back instead of propagating zeros.
bbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/SvgImageCreatorImp.java Ensures generated SVGs use non-zero defaults and don’t adopt zero dimensions after resize/detection failures.
bbb-common-web/src/main/java/org/bigbluebutton/presentation/handlers/ImageResolutionServiceHandler.java Adds warn-level visibility when image resolution parsing fails and returns 0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kepstin

kepstin commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

In addition to fixing the code which determines image size, some handling should be added in the code where the numbers are used (in hasura?) to protect against division by zero errors.

@antobinary
antobinary requested a review from gustavotrott April 8, 2026 14:32
@sonarqubecloud

sonarqubecloud Bot commented Apr 8, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
bbb-graphql-server/bbb_schema.sql (1)

1567-1570: Division-by-zero protection is correctly implemented.

The NULLIF(..., 0) approach properly prevents SQL division errors when width or height is zero. These columns will return NULL when both dimensions are zero.

Client-side has secondary protection, but primary guard should be strengthened. The whiteboard component at line 983 uses scaledViewBoxWidth === 0 which doesn't catch null values. While a secondary protection exists at line 991 via throwIfInvalid(currentZoomLevel) that will catch the resulting NaN or Infinity, the primary guard should be improved for clarity and earlier detection:

if (!scaledViewBoxWidth || !scaledViewBoxHeight) {
  throw new Error(...);
}

This catches both zero and null/undefined, aligning with the retrieved learning: "NaN or Inf values have been observed in pan/zoom related fields due to unusual window sizes."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bbb-graphql-server/bbb_schema.sql` around lines 1567 - 1570, The SQL NULLIF
protection is fine, but the whiteboard component's primary guard should catch
null as well as zero: replace the existing explicit zero check on
scaledViewBoxWidth/scaledViewBoxHeight with a falsy check (e.g., if
(!scaledViewBoxWidth || !scaledViewBoxHeight) { throw new Error(...) }) so
null/undefined are rejected earlier; update the guard near the
scaledViewBoxWidth/scaledViewBoxHeight checks (before calling
throwIfInvalid(currentZoomLevel)) to perform this stricter validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@bbb-graphql-server/bbb_schema.sql`:
- Around line 1567-1570: The SQL NULLIF protection is fine, but the whiteboard
component's primary guard should catch null as well as zero: replace the
existing explicit zero check on scaledViewBoxWidth/scaledViewBoxHeight with a
falsy check (e.g., if (!scaledViewBoxWidth || !scaledViewBoxHeight) { throw new
Error(...) }) so null/undefined are rejected earlier; update the guard near the
scaledViewBoxWidth/scaledViewBoxHeight checks (before calling
throwIfInvalid(currentZoomLevel)) to perform this stricter validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75c0eba8-da5e-49df-a315-40909159c089

📥 Commits

Reviewing files that changed from the base of the PR and between 56ac1b8 and 79d3257.

📒 Files selected for processing (1)
  • bbb-graphql-server/bbb_schema.sql

@gustavotrott gustavotrott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was not able to reproduce the issue to confirm whether it fixes the issue.
But the improvement seems good.

@antobinary
antobinary merged commit 91e824a into bigbluebutton:v3.0.x-develop Apr 10, 2026
56 of 58 checks passed
@github-actions

Copy link
Copy Markdown

🚨 Automated tests failed

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.

5 participants