Skip to content

fix: prevent crash when writing to a closed wrap writer - #699

Merged
taciturnaxolotl merged 1 commit into
mainfrom
fix/wrapwriter-use-after-close
Jun 12, 2026
Merged

taciturnaxolotl merged 1 commit into
mainfrom
fix/wrapwriter-use-after-close

Conversation

@taciturnaxolotl

Copy link
Copy Markdown
Member

Summary

A WrapWriter panics with a nil pointer dereference if it is written to after being closed. Close() returns the internal ANSI parser to a sync.Pool and nils the reference, but Write dereferenced it unconditionally.

This surfaces when nested writer chains tear down out of order: closing an outer writer can flush a trailing style or link reset back through a writer that was already closed, crashing the program. Glamour's block rendering hits this when a styled run is left open across an indent or margin boundary (common when rendering partial/streamed markdown).

Fix

Treat a write after close as a safe no-op rather than a fatal panic. A closed writer has nothing useful to do with further bytes, so swallowing them keeps out-of-order teardown safe.

Test

TestWrapWriterWriteAfterClose writes after close and asserts no panic. It fails (nil pointer dereference) without the guard and passes with it.

πŸ’˜ Generated with Crush

Closing a WrapWriter returns its ANSI parser to a pool and clears the
reference. When nested writer chains tear down out of order, a trailing
style or link reset can be flushed back through a writer that was already
closed, dereferencing a nil parser and crashing the program.

Treat writes after close as a no-op so this teardown ordering is safe
rather than fatal.
@taciturnaxolotl
taciturnaxolotl merged commit b00306c into main Jun 12, 2026
13 checks passed
@taciturnaxolotl
taciturnaxolotl deleted the fix/wrapwriter-use-after-close branch June 12, 2026 13:44
eleboucher pushed a commit to eleboucher/apoci that referenced this pull request Jun 12, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [charm.land/lipgloss/v2](https://github.com/charmbracelet/lipgloss) | `v2.0.3` β†’ `v2.0.4` | ![age](https://developer.mend.io/api/mc/badges/age/go/charm.land%2flipgloss%2fv2/v2.0.4?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/charm.land%2flipgloss%2fv2/v2.0.3/v2.0.4?slim=true) |

---

### Release Notes

<details>
<summary>charmbracelet/lipgloss (charm.land/lipgloss/v2)</summary>

### [`v2.0.4`](https://github.com/charmbracelet/lipgloss/releases/tag/v2.0.4)

[Compare Source](charmbracelet/lipgloss@v2.0.3...v2.0.4)

### Mini Crash Patch

Hi! This is a small patch to fix a writer-related panic. Thanks for using Lip Gloss!

#### Changelog

##### Fixed

- [`fefa41d`](charmbracelet/lipgloss@fefa41d): fix: prevent crash when writing to a closed wrap writer ([#&#8203;699](charmbracelet/lipgloss#699)) ([@&#8203;taciturnaxolotl](https://github.com/taciturnaxolotl))

##### Docs

- [`40ec0e6`](charmbracelet/lipgloss@40ec0e6): docs: fix typo in table comment ([#&#8203;641](charmbracelet/lipgloss#641)) ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))
- [`a4d0b40`](charmbracelet/lipgloss@a4d0b40): docs: restore missing diaereses ([#&#8203;664](charmbracelet/lipgloss#664)) ([@&#8203;meowgorithm](https://github.com/meowgorithm))

##### Chore

- [`aa91b99`](charmbracelet/lipgloss@aa91b99): chore: remove CODEOWNERS ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))
- [`9cbfe8b`](charmbracelet/lipgloss@9cbfe8b): chore(lint): exclude revive naming linter ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))

***

<a href="https://charm.land/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-banner-next.jpg" width="400"></a>

Thoughts? Questions? We love hearing from you. Feel free to reach out on [X](https://x.com/charmcli), [Discord](https://charm.land/discord), [Slack](https://charm.land/slack), [The Fediverse](https://mastodon.social/@&#8203;charmcli), [Bluesky](https://bsky.app/profile/charm.land).

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/apoci/pulls/78
dgalanberasaluce pushed a commit to dgalanberasaluce/maximus-cli that referenced this pull request Jun 23, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [charm.land/lipgloss/v2](https://github.com/charmbracelet/lipgloss) | `v2.0.3` β†’ `v2.0.4` | ![age](https://developer.mend.io/api/mc/badges/age/go/charm.land%2flipgloss%2fv2/v2.0.4?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/charm.land%2flipgloss%2fv2/v2.0.3/v2.0.4?slim=true) |
| [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) | `v1.14.45` β†’ `v1.14.47` | ![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fmattn%2fgo-sqlite3/v1.14.47?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fmattn%2fgo-sqlite3/v1.14.45/v1.14.47?slim=true) |

---

### Release Notes

<details>
<summary>charmbracelet/lipgloss (charm.land/lipgloss/v2)</summary>

### [`v2.0.4`](https://github.com/charmbracelet/lipgloss/releases/tag/v2.0.4)

[Compare Source](charmbracelet/lipgloss@v2.0.3...v2.0.4)

### Mini Crash Patch

Hi! This is a small patch to fix a writer-related panic. Thanks for using Lip Gloss!

#### Changelog

##### Fixed

- [`fefa41d`](charmbracelet/lipgloss@fefa41d): fix: prevent crash when writing to a closed wrap writer ([#&#8203;699](charmbracelet/lipgloss#699)) ([@&#8203;taciturnaxolotl](https://github.com/taciturnaxolotl))

##### Docs

- [`40ec0e6`](charmbracelet/lipgloss@40ec0e6): docs: fix typo in table comment ([#&#8203;641](charmbracelet/lipgloss#641)) ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))
- [`a4d0b40`](charmbracelet/lipgloss@a4d0b40): docs: restore missing diaereses ([#&#8203;664](charmbracelet/lipgloss#664)) ([@&#8203;meowgorithm](https://github.com/meowgorithm))

##### Chore

- [`aa91b99`](charmbracelet/lipgloss@aa91b99): chore: remove CODEOWNERS ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))
- [`9cbfe8b`](charmbracelet/lipgloss@9cbfe8b): chore(lint): exclude revive naming linter ([@&#8203;aymanbagabas](https://github.com/aymanbagabas))

***

<a href="https://charm.land/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-banner-next.jpg" width="400"></a>

Thoughts? Questions? We love hearing from you. Feel free to reach out on [X](https://x.com/charmcli), [Discord](https://charm.land/discord), [Slack](https://charm.land/slack), [The Fediverse](https://mastodon.social/@&#8203;charmcli), [Bluesky](https://bsky.app/profile/charm.land).

</details>

<details>
<summary>mattn/go-sqlite3 (github.com/mattn/go-sqlite3)</summary>

### [`v1.14.47`](mattn/go-sqlite3@v1.14.46...v1.14.47)

[Compare Source](mattn/go-sqlite3@v1.14.46...v1.14.47)

### [`v1.14.46`](mattn/go-sqlite3@v1.14.45...v1.14.46)

[Compare Source](mattn/go-sqlite3@v1.14.45...v1.14.46)

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

πŸ‘» **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My43My4yIiwidXBkYXRlZEluVmVyIjoiNDMuNzMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://forgejo.internal/forgejo_admin/maximus/pulls/16
Co-authored-by: Renovate Bot <renovatebot@forgejo.internal>
Co-committed-by: Renovate Bot <renovatebot@forgejo.internal>
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.

2 participants