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

Sanitize measure function results #44557

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <iostream>

#include <yoga/debug/AssertFatal.h>
#include <yoga/debug/Log.h>
#include <yoga/node/Node.h>
#include <yoga/numeric/Comparison.h>

Expand Down Expand Up @@ -49,12 +50,29 @@ Node::Node(Node&& node) noexcept
}

YGSize Node::measure(
float width,
float availableWidth,
MeasureMode widthMode,
float height,
float availableHeight,
MeasureMode heightMode) {
return measureFunc_(
this, width, unscopedEnum(widthMode), height, unscopedEnum(heightMode));
const auto size = measureFunc_(
this,
availableWidth,
unscopedEnum(widthMode),
availableHeight,
unscopedEnum(heightMode));

if (yoga::isUndefined(size.height) || size.height < 0 ||
yoga::isUndefined(size.width) || size.width < 0) {
yoga::log(
this,
LogLevel::Error,
"Measure function returned an invalid dimension to Yoga: [width=%f, height=%f]",
size.width,
size.height);
return {.width = 0.0f, .height = 0.0f};
}

return size;
}

float Node::baseline(float width, float height) const {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class YG_EXPORT Node : public ::YGNode {
}

YGSize measure(
float width,
float availableWidth,
MeasureMode widthMode,
float height,
float availableHeight,
MeasureMode heightMode);

bool hasBaselineFunc() const noexcept {
Expand Down
Loading