fix(sections-editor): add bounds checks to array field operations - #6109
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(sections-editor): add bounds checks to array field operations#6109pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds defensive bounds checks to array field operations (
openItem,duplicateItem,toggleItemHidden,removeItem,updateItem) to prevent undefined item access if entry indices ever become desynchronized with items.Why This Matters
The rendering loop already has a defensive bounds check (line 551-552:
if (item === undefined) return null;), but the action handlers were missing equivalent checks. If entry indices ever become out-of-bounds due to a bug inresizeArrayEntries,removeEntryAt, orinsertEntryAfter, these handlers would operate on undefined items, leading to crashes or silent failures in label computation, item cloning, or hidden-item toggling.This fix ensures all array operations fail safely on invalid indices instead of propagating undefined values.
Changes
openItem(): Guard againstindex < 0 || index >= items.lengthduplicateItem(): Guard againstindex < 0 || index >= items.lengthtoggleItemHidden(): Guard againstindex < 0 || index >= items.lengthremoveItem(): Guard againstindex < 0 || index >= items.lengthupdateItem(): Guard againstindex < 0 || index >= items.lengthVerification
bunx tsc --noEmit) green in apps/webbunx oxlint) clean on modified filebun run fmtTesting Command
bun test apps/web/src/components/sections-editor/ bunx tsc --noEmit --cwd apps/web bunx oxlint apps/web/src/components/sections-editor/fields/array-field.tsxSummary by cubic
Prevents undefined item access in the sections editor by adding bounds checks to array field handlers. Previously these handlers acted on out-of-range indices; now they return early to avoid crashes and unintended mutations.
Details for review
index < 0 || index >= items.lengthguards toopenItem,duplicateItem,toggleItemHidden,removeItem, andupdateIteminapps/web/src/components/sections-editor/fields/array-field.tsx;openItemalso preserves thesuppressClickRefcheck.resizeArrayEntries,removeEntryAt, orinsertEntryAfter.Rollout
Written for commit e91b8da. Summary will update on new commits.