Skip to content

Conversation

@Ayush-Raj-Chourasia
Copy link

@Ayush-Raj-Chourasia Ayush-Raj-Chourasia commented Oct 4, 2025

What is the current behavior?

Setting a string value (e.g., "300") for width or height in ImageAssetOptions causes a crash on Android API level 22 with the error:
java.lang.IllegalArgumentException: bitmap size exceeds 32 bits.
This happens because the string is not coerced to a number, resulting in an invalid bitmap size.

What is the new behavior?

The function getRequestedImageSize now coerces width and height to numbers if they are passed as strings. This prevents the bitmap size error on Android and ensures compatibility with older API levels.

Fixes/Implements/Closes #6289.

@NathanWalker NathanWalker requested a review from Copilot October 29, 2025 19:41
@nx-cloud
Copy link

nx-cloud bot commented Oct 29, 2025

View your CI Pipeline Execution ↗ for commit b9ee846

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 4m 10s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-29 19:49:47 UTC

Copy link

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

This PR adds string-to-number coercion logic for width and height parameters in the getRequestedImageSize function. While the ImageAssetOptions interface specifies these as optional numbers, this change adds runtime handling to convert string values to numbers if they are provided.

  • Added type checking and parsing for width and height values that may be strings
  • Maintained existing aspect ratio calculation and dimension logic
  • Applied consistent indentation changes to the function body
Comments suppressed due to low confidence (1)

packages/core/image-asset/image-asset-common.ts:1

  • The height parsing is using reqWidth instead of reqHeight on line 59. This should be parseInt(reqHeight, 10).
import { ImageAsset as ImageAssetDefinition, ImageAssetOptions } from '.';

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

Comment on lines +56 to +59
reqWidth = parseInt(reqWidth, 10);
}
if (typeof reqHeight === 'string') {
reqHeight = parseInt(reqHeight, 10);
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The ImageAssetOptions interface defines width and height as optional number types, but this code suggests they could be strings at runtime. Consider using Number() or adding explicit NaN validation after parseInt(), as parseInt() can return NaN for invalid strings, which would propagate through calculations.

Suggested change
reqWidth = parseInt(reqWidth, 10);
}
if (typeof reqHeight === 'string') {
reqHeight = parseInt(reqHeight, 10);
const parsedWidth = parseInt(reqWidth, 10);
reqWidth = isNaN(parsedWidth) ? Math.min(src.width, Screen.mainScreen.widthPixels) : parsedWidth;
}
if (typeof reqHeight === 'string') {
const parsedHeight = parseInt(reqHeight, 10);
reqHeight = isNaN(parsedHeight) ? Math.min(src.height, Screen.mainScreen.heightPixels) : parsedHeight;

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +60
let reqWidth = options.width || Math.min(src.width, Screen.mainScreen.widthPixels);
let reqHeight = options.height || Math.min(src.height, Screen.mainScreen.heightPixels);

return {
width: reqWidth,
height: reqHeight,
};
if (typeof reqWidth === 'string') {
reqWidth = parseInt(reqWidth, 10);
}
if (typeof reqHeight === 'string') {
reqHeight = parseInt(reqHeight, 10);
}
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The string coercion checks on lines 55-60 occur after using the fallback logic on lines 52-53. If options.width or options.height are strings, the || operator won't trigger the fallback because non-empty strings are truthy. The string type checks should occur before or be integrated with the fallback logic to ensure proper behavior.

Copilot uses AI. Check for mistakes.
@NathanWalker
Copy link
Contributor

Hey! Thanks so much for opening a pull request!

A prior PR was opened to solve this issue here: #10862 which will be merging.

Thanks again, and we look forward to seeing more PRs from you in the future! ❤️

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.

Setting string value to width or height of ImageAssetOptions results in an error on android

2 participants