fix: truncate long lines before tfmask to prevent bufio.Scanner crash on apply#426
Open
bennymagid wants to merge 5 commits intodflook:mainfrom
Open
fix: truncate long lines before tfmask to prevent bufio.Scanner crash on apply#426bennymagid wants to merge 5 commits intodflook:mainfrom
bennymagid wants to merge 5 commits intodflook:mainfrom
Conversation
tfmask is a Go binary that reads plan output line-by-line using bufio.Scanner, which has a default 64KB buffer limit. Terraform resources that embed large base64 blobs in their plan output (e.g. google_api_gateway_api_config with openapi_documents) produce single lines that exceed this limit. When tfmask crashes mid-pipe, terraform receives SIGPIPE and exits with a non-standard code (not 0 or 2). PIPESTATUS[0] then captures that bad code, neither branch of the PLAN_EXIT check matches, set_output changes is never called, and the apply step is skipped with "No plan changes detected". Fix: add a Python pre-processor before tfmask that truncates any line exceeding 65000 chars. This preserves tfmask's secret-masking for all normal lines while preventing it from crashing on oversized blob lines. The truncated content only affects the human-readable plan display in plan.txt — it has no effect on whether changes are detected or applied. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…content Instead of truncating lines that exceed bufio.Scanner's 64KB limit, split them into 60KB chunks with a sentinel prefix (##TF_CHUNK:i/total/content) before tfmask, then reassemble after. This prevents the tfmask crash while keeping the complete plan output intact for downstream consumers.
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.
Describe your changes
$TFMASKin the plan pipeline[line truncated for display]suffix before reaching tfmaskWhy
tfmaskuses Go'sbufio.Scannerwhich has a 64KB per-line limit. Terraform resources that embed large base64 blobs in plan output (e.g.google_api_gateway_api_configwithopenapi_documents) produce single lines exceeding this limit.When tfmask crashes mid-pipe, terraform receives SIGPIPE and exits with a non-standard code.
PIPESTATUS[0]captures that bad code, neitherPLAN_EXIT -eq 0norPLAN_EXIT -eq 2matches,set_output changesis never called, and the apply step is silently skipped with "No plan changes detected" — even when there are real changes to apply.Test Plan
bufio.Scanner: token too longerror in CI logs through the pipeline exit code flow to the skipped applyGCP Changes
None