pytorch
a31aab71 - Fix windows workflow RCE (#81835)

Commit
2 years ago
Fix windows workflow RCE (#81835) This is to avoid having unescaped inputs wreaking havoc internally like in the Windows workflow, for example, https://github.com/pytorch/pytorch/runs/7438650352 The issue is triggered by the PR body in https://github.com/pytorch/pytorch/pull/81755, so I copy the body below to test this fix. The Windows test workflow should pass instead of failing with the cryptic `> was unexpected at this time` error message and a 255 exit error code. TESTING PR BODY BELOW: ### The problem This original regex abuses .* in combination with `re.DOTALL` and leads to a catastrophic backtracking perf issue when there is no match. When it happens, test_doc_template will run "forever" and timeout. Here is an example timeout test https://github.com/pytorch/pytorch/runs/7413337595 Another minor issue with this regex is that it won't matches concatenated doc string like `"""FOO""" + """BAR"""`, which is used for some API `_torch_docs.py` ### The fix * Remove most of the match all .* usage. I have tested to make sure that the test finishes even when there is no match, i.e. it fails successfully * Update the regex to match all the following cases before and after linting (You can also try it out on https://pythex.org): BEFORE ``` add_docstr(torch.abs, r""" abs(input, *, out=None) -> Tensor Computes the absolute value of each element in :attr:`input`. .. math:: \text{out}_{i} = |\text{input}_{i}| """ + r""" Args: {input} Keyword args: {out} Example:: >>> torch.abs(torch.tensor([-1, -2, 3])) tensor([ 1, 2, 3]) """.format(**common_args)) add_docstr(torch.absolute, r""" absolute(input, *, out=None) -> Tensor Alias for :func:`torch.abs` """) ``` AFTER ``` add_docstr( torch.abs, r""" abs(input, *, out=None) -> Tensor Computes the absolute value of each element in :attr:`input`. .. math:: \text{out}_{i} = |\text{input}_{i}| """ + r""" Args: {input} Keyword args: {out} Example:: >>> torch.abs(torch.tensor([-1, -2, 3])) tensor([ 1, 2, 3]) """.format( **common_args ), ) add_docstr( torch.absolute, r""" absolute(input, *, out=None) -> Tensor Alias for :func:`torch.abs` """, ) ``` This will unblock https://github.com/pytorch/pytorch/pull/81643 Pull Request resolved: https://github.com/pytorch/pytorch/pull/81835 Approved by: https://github.com/janeyx99
Author
Committer
Parents
Loading