Skip to content

Commit

Permalink
Check for out of bound reads (#523)
Browse files Browse the repository at this point in the history
* Check for out of bound reads

* Added changelog entry

* Do an early return in seperator for the last index

* Changed order in if statement for readability
This also gets rid of the dataLength variable

* Removed unnecessary check

Co-authored-by: Talha Naqvi <naqvitalha@gmail.com>
  • Loading branch information
Arjan-Zuidema and naqvitalha committed Jul 15, 2022
1 parent a905dab commit 2efb3f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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
13 changes: 10 additions & 3 deletions src/FlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,18 @@ class FlashList<T> extends React.PureComponent<
}

private separator = (index: number) => {
const leadingItem = this.props.data?.[index];
const trailingItem = this.props.data?.[index + 1];
if (trailingItem === undefined) {
// Make sure we have data and don't read out of bounds
if (
this.props.data === null ||
this.props.data === undefined ||
index + 1 >= this.props.data.length
) {
return null;
}

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

const props = {
leadingItem,
trailingItem,
Expand Down

0 comments on commit 2efb3f2

Please sign in to comment.