fix segfault when input shorter than all patterns#6071
Closed
ebernhardson wants to merge 1 commit intofacebook:masterfrom
Closed
fix segfault when input shorter than all patterns#6071ebernhardson wants to merge 1 commit intofacebook:masterfrom
ebernhardson wants to merge 1 commit intofacebook:masterfrom
Conversation
Contributor
|
This pull request has been imported into Phabricator, and discussion and review of the diff will take place at https://reviews.facebook.net/D44973 |
Contributor
|
Reproduction case for the crash that this patch fixes: <?php
$map = array(
'ﭐ' => 'ٱ', 'ﭑ' => 'ٱ', 'ﭒ' => 'ٻ', 'ﭓ' => 'ٻ', 'ﭔ' => 'ٻ', 'ﭕ' => 'ٻ', 'ﭖ' => 'پ',
'ﭗ' => 'پ', 'ﭘ' => 'پ', 'ﭙ' => 'پ', 'ﭚ' => 'ڀ', 'ﭛ' => 'ڀ', 'ﭜ' => 'ڀ', 'ﭝ' => 'ڀ',
'ﭞ' => 'ٺ', 'ﭟ' => 'ٺ', 'ﭠ' => 'ٺ', 'ﭡ' => 'ٺ', 'ﭢ' => 'ٿ', 'ﭣ' => 'ٿ', 'ﭤ' => 'ٿ',
'ﭥ' => 'ٿ', 'ﭦ' => 'ٹ', 'ﭧ' => 'ٹ', 'ﭨ' => 'ٹ', 'ﭩ' => 'ٹ', 'ﭪ' => 'ڤ', 'ﭫ' => 'ڤ',
'ﭬ' => 'ڤ', 'ﭭ' => 'ڤ', 'ﭮ' => 'ڦ', 'ﭯ' => 'ڦ', 'ﭰ' => 'ڦ', 'ﭱ' => 'ڦ', 'ﭲ' => 'ڄ',
'ﭳ' => 'ڄ', 'ﭴ' => 'ڄ', 'ﭵ' => 'ڄ', 'ﭶ' => 'ڃ', 'ﭷ' => 'ڃ', 'ﭸ' => 'ڃ', 'ﭹ' => 'ڃ',
'ﭺ' => 'چ', 'ﭻ' => 'چ', 'ﭼ' => 'چ', 'ﭽ' => 'چ', 'ﭾ' => 'ڇ', 'ﭿ' => 'ڇ', 'ﮀ' => 'ڇ',
'ﮁ' => 'ڇ', 'ﮂ' => 'ڍ', 'ﮃ' => 'ڍ', 'ﮄ' => 'ڌ', 'ﮅ' => 'ڌ', 'ﮆ' => 'ڎ', 'ﮇ' => 'ڎ',
'ﮈ' => 'ڈ', 'ﮉ' => 'ڈ', 'ﮊ' => 'ژ', 'ﮋ' => 'ژ', 'ﮌ' => 'ڑ', 'ﮍ' => 'ڑ', 'ﮎ' => 'ک',
'ﮏ' => 'ک', 'ﮐ' => 'ک',
);
strtr( 'ab', $map ); |
1737868 to
1c4d1dc
Compare
Contributor
Author
|
apologies for not finishing this up yet, still seeing an occasional crash in this code in prod and have not traced it down yet. |
1c4d1dc to
dd8fe89
Compare
dd8fe89 to
8b9d870
Compare
Contributor
|
We close pull requests after changes are requested on phabricator for > 1 week. Will re-open when changes are made. |
Contributor
|
Author is coming back to this, per discussion on #6384 |
When the input string is shorter than the shortest input pattern the last position to visit is set to a negative, which due to the unsigned nature rolls over to a very big number. Fix short circuits and returns input string when all patterns are longer than the input string. The LRU cache is holding onto StringData between requests through the PatAndRepl class, but StringData uses the request-local allocator. To ensure the patterns and replacements survive across requests they are now copied into a std::string. Additionally this included a potential race condition under concurrency. initTables() could be running in one thread when the WuManberReplacement is pulled from the LRU cache. This second execution could start running the replacement before initTables() has completed. The class has been adjusted so it can be declared const at construction and does not change its internal state.
8b9d870 to
397be88
Compare
jwatzman
pushed a commit
that referenced
this pull request
Oct 21, 2015
Summary: When the input string is shorter than the shortest input pattern the last position to visit is set to -1. Patch short circuits and returns input string when all patterns are longer than the input string. Closes #6071 Reviewed By: jwatzman Differential Revision: D2367627 fb-gh-sync-id: 704ab038e68145916460c890bf6522dd62910af8
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.
When the input string is shorter than the shortest input
pattern the last position to visit is set to -1. Patch
short circuits and returns input string when all patterns
are longer than the input string.