Skip to content

Conversation

@Rocketknight1
Copy link
Member

@Rocketknight1 Rocketknight1 commented Mar 11, 2025

We had an overly-complex regex designed to capture docstrings, and as a result it has potentially exponential runtime for malicious inputs. This PR makes the following simplifying changes:

  • Explicit calls to re.compile without saving the compiled object are removed - these only hurt performance (see note)
  • re.MULTILINE was removed because this only affects the behaviour of ^ and $ characters, which are not used in this regex
  • Over-complex non-capturing group replaced with much simpler regex, because re.DOTALL allows .*? to go through newlines

cc @Michellehbn!

@Rocketknight1 Rocketknight1 marked this pull request as ready for review March 11, 2025 15:13
@github-actions github-actions bot requested a review from ArthurZucker March 11, 2025 15:13
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Rocketknight1 Rocketknight1 force-pushed the fix-doc-preprocess branch 2 times, most recently from fd58c65 to 1e2d691 Compare March 13, 2025 14:10
@Rocketknight1 Rocketknight1 requested review from ydshieh and removed request for ArthurZucker March 13, 2025 17:37
@Rocketknight1
Copy link
Member Author

cc @ydshieh for review as the original author (I think!) of the function

Copy link
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. My brain is broken every time I see such regex ....

(I'm not the author of this, my previous PR just reverted a previously reverted PR)

@Rocketknight1 Rocketknight1 merged commit 8cb522b into main Mar 14, 2025
24 checks passed
@Rocketknight1 Rocketknight1 deleted the fix-doc-preprocess branch March 14, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants