Repository navigation
Conversation
Check the gob decode error and nil Headers before dereferencing the cached Response. A truncated or corrupt CacheDir file (interrupted write, disk full, external tampering) left resp.Headers nil and the subsequent *resp.Headers deref crashed the process with a SIGSEGV. On any decode error, remove the corrupt file and fall back to a live fetch.
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.
Fixes #914.
Problem
When
CacheDiris enabled, a corrupt or truncated cache file crashes the process with a nil-pointer dereference (SIGSEGV). InhttpBackend.Cachethe gob decode error is ignored, and on a partial/corrupt file the decodedResponse.Headersis left nil; the following*resp.Headersderef then panics. There is norecover(), so the process (or an async worker goroutine) crashes.This can be triggered by an interrupted write, a disk-full condition, a crash mid-write, or external tampering.
Fix
Check the gob decode error and nil
Headersbefore dereferencing the cachedResponse. On any decode error, remove the corrupt file and fall through to a live fetch. Behavior for valid cache files is unchanged.Test
Adds
TestCorruptCacheFileFallsBackToFetch(http_backend_test.go): pre-writes a truncated gob at the correct cache path for the normalized URL, then visits and asserts no panic, a live fetch occurs with the correct body, and the corrupt file is replaced with a valid cache entry. Without the fix this test panics with SIGSEGV; with the fix the full suite passes.