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

Check for out of bound reads #523

Merged
merged 7 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Fixed out of bound read from data
- https://github.com/Shopify/flash-list/pull/523

- Added JS only fallbacks for unsupported platforms
- https://github.com/Shopify/flash-list/pull/518
Expand Down
16 changes: 14 additions & 2 deletions src/FlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,20 @@ class FlashList<T> extends React.PureComponent<
}

private separator = (index: number) => {
const leadingItem = this.props.data?.[index];
const trailingItem = this.props.data?.[index + 1];
const dataLength = this.props.data?.length || 0;

// Make sure we have data and don't read out of bounds
if (
index + 1 >= dataLength ||
this.props.data === null ||
this.props.data === undefined
) {
return null;
}
fortmarek marked this conversation as resolved.
Show resolved Hide resolved

const leadingItem = this.props.data[index];
const trailingItem = this.props.data[index + 1];

if (trailingItem === undefined) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry fora yet-another change, I always find some small improvement 😄

This check should no longer be necessary since we ensure in the previous if that trailingItem exists

Suggested change
if (trailingItem === undefined) {
return null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. Also fixed!

Expand Down