Repository navigation
fix(bbb-web): Prevent SVGs From Being Generated With Zero Value Dimensions - #24872
Conversation
WalkthroughUpdated 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)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (3)
bbb-common-web/src/main/java/org/bigbluebutton/presentation/handlers/ImageResolutionServiceHandler.javabbb-common-web/src/main/java/org/bigbluebutton/presentation/imp/SvgImageCreatorImp.javabbb-common-web/src/main/scala/org/bigbluebutton/api2/MsgBuilder.scala
There was a problem hiding this comment.
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<=0as invalid when probing SVG dimensions, forcing a fallback to defaults/other resolution strategies. - Use
MAX_SVG_WIDTH/MAX_SVG_HEIGHTas 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.
|
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. |
|
There was a problem hiding this comment.
🧹 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 whenwidthorheightis zero. These columns will returnNULLwhen both dimensions are zero.Client-side has secondary protection, but primary guard should be strengthened. The whiteboard component at line 983 uses
scaledViewBoxWidth === 0which doesn't catchnullvalues. While a secondary protection exists at line 991 viathrowIfInvalid(currentZoomLevel)that will catch the resultingNaNorInfinity, 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
📒 Files selected for processing (1)
bbb-graphql-server/bbb_schema.sql
gustavotrott
left a comment
There was a problem hiding this comment.
I was not able to reproduce the issue to confirm whether it fixes the issue.
But the improvement seems good.
91e824a
into
bigbluebutton:v3.0.x-develop
🚨 Automated tests failed |



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.