Merge pull request #12725 from acozzette/cherrypick-12104-fix

Fix crash in #12104 (cherry-pick)