Skip to content

[internal/wclayer]: clear currentIsDir in reset deferred cleanup#2787

Merged
anmaxvl merged 1 commit into
microsoft:mainfrom
anmaxvl:fix/clear-currentisdir-on-reset-error
Jun 22, 2026
Merged

[internal/wclayer]: clear currentIsDir in reset deferred cleanup#2787
anmaxvl merged 1 commit into
microsoft:mainfrom
anmaxvl:fix/clear-currentisdir-on-reset-error

Conversation

@anmaxvl

@anmaxvl anmaxvl commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

When reset returns an error from inside the currentIsDir block (e.g.
safefile.RemoveRelative or br.Next fails), the deferred cleanup closes
currentFile and sets it to nil, but previously left currentIsDir true.
A subsequent call to reset (e.g. from Close after a failed Add) would
then enter the currentIsDir block, assign r := w.currentFile (nil),
and panic at r.Seek.

Fix: set w.currentIsDir = false in the deferred cleanup alongside the
other currentFile fields so all file-related state is consistently
cleared even on the error path.

Adds a test covering this exact scenario: error inside the currentIsDir
block, followed by a second reset call that must not panic.

Assisted-by: Github-Copilot

When reset returns an error from inside the currentIsDir block (e.g.
safefile.RemoveRelative or br.Next fails), the deferred cleanup closes
currentFile and sets it to nil, but previously left currentIsDir true.
A subsequent call to reset (e.g. from Close after a failed Add) would
then enter the currentIsDir block, assign r := w.currentFile (nil),
and panic at r.Seek.

Fix: set w.currentIsDir = false in the deferred cleanup alongside the
other currentFile fields so all file-related state is consistently
cleared even on the error path.

Adds a test covering this exact scenario: error inside the currentIsDir
block, followed by a second reset call that must not panic.

Assisted-by: Github-Copilot
Signed-off-by: Maksim An <maksiman@microsoft.com>
@anmaxvl anmaxvl requested a review from a team as a code owner June 22, 2026 17:51
@anmaxvl anmaxvl merged commit d0dedde into microsoft:main Jun 22, 2026
19 checks passed
@anmaxvl anmaxvl deleted the fix/clear-currentisdir-on-reset-error branch June 22, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants