From 2efb3f263caa50b9ddfa58fb9188c85a0719d4e9 Mon Sep 17 00:00:00 2001 From: Arjan Zuidema Date: Sat, 16 Jul 2022 01:34:21 +0200 Subject: [PATCH] Check for out of bound reads (#523) * 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 --- CHANGELOG.md | 2 ++ src/FlashList.tsx | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0098f8250..db401fb10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/FlashList.tsx b/src/FlashList.tsx index f364e803f..d047b3da3 100644 --- a/src/FlashList.tsx +++ b/src/FlashList.tsx @@ -543,11 +543,18 @@ class FlashList 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,