diff --git a/README.md b/README.md index 67c708a7..c0265f5d 100644 --- a/README.md +++ b/README.md @@ -39,31 +39,31 @@ Specifically, `_RegexParser` contains the parser for regular expression literals ### Branching scheme -#### Development branch - The `main` branch is the branch for day-to-day development. Generally, you should create PRs against this branch. -#### Swift integration branches - Branches whose name starts with `swift/` are Swift integration branches similar to those in [apple/llvm-project](https://github.com/apple/llvm-project). For each branch, dropping the `swift/` prefix is the corresponding branch in [apple/swift](https://github.com/apple/swift). +This package's `main` branch will automatically integrate with Swift's `main` branch. + | apple/swift branch | apple/swift-experimental-string-processing branch | | ------------------- | ----------------------------------------------------- | -| main | swift/main | +| main | main | | release/5.7 | swift/release/5.7 | | ... | swift/... | A pair of corresponding branches are expected to build successfully together and pass all tests. -### Integration workflow +### Running Package CI and full Swift CI To integrate the latest changes in apple/swift-experimental-string-processing to apple/swift, carefully follow the workflow: -- Create pull requests. - - Create a branch from a commit on `main` that you would like to integrate into `swift/main`. - - Create a pull request in apple/swift-experimental-string-processing from that branch to `swift/main`, e.g. "[Integration] main () -> swift/main". +- Run package CI + - In the pull request, trigger package CI using +``` +@swift-ci please test +``` +- Run full Swift CI for any changes to public or SPI interfaces or the `_RegexParser` module. - If apple/swift needs to be modified to work with the latest `main` in apple/swift-experimental-string-processing, create a pull request in apple/swift. **Note:** Since CI in apple/swift-experimental-string-processing has not yet been set up to run full toolchain tests, you should create a PR in apple/swift regardless; if the integartion does not require changing apple/swift, create a dummy PR in apple/swift by changing the README and just not merge it in the end. -- Trigger CI. - In the apple/swift-experimental-string-processing pull request, trigger CI using the following command (replacing `` with the apple/swift pull request number, if any): ``` apple/swift# # use this line only if there is an corresponding apple/swift PR @@ -75,7 +75,9 @@ To integrate the latest changes in apple/swift-experimental-string-processing to @swift-ci please test ``` - Merge when approved. - - Merge the pull request in apple/swift-experimental-string-processing as a **merge commit**. + - Merge the PR in apple/swift-experimental-string-processing: + - as a squash or rebase if against main (the development branch). + - as a merge commit if it's a merge from main to swift/release/x.y. - Merge the pull request in apple/swift (if any). ### Development notes diff --git a/Sources/_RegexParser/Regex/Parse/Parse.swift b/Sources/_RegexParser/Regex/Parse/Parse.swift index 1fdadd8d..3ec852aa 100644 --- a/Sources/_RegexParser/Regex/Parse/Parse.swift +++ b/Sources/_RegexParser/Regex/Parse/Parse.swift @@ -523,6 +523,19 @@ extension Parser { mutating func parseCustomCharacterClass( _ start: Source.Located ) -> CustomCC { + // Excessively nested recursion is a common DOS attack, so limit + // our recursion. + context.parseDepth += 1 + defer { context.parseDepth -= 1 } + guard context.parseDepth < context.maxParseDepth else { + self.errorAtCurrentPosition(.nestingTooDeep) + + // This is not generally recoverable and further errors will be + // incorrect + diags.suppressFurtherDiagnostics = true + return .init(start, [], start.location) + } + let alreadyInCCC = context.isInCustomCharacterClass context.isInCustomCharacterClass = true defer { context.isInCustomCharacterClass = alreadyInCCC } diff --git a/Tests/RegexTests/ParseTests.swift b/Tests/RegexTests/ParseTests.swift index cbb9e6b3..7f0dd811 100644 --- a/Tests/RegexTests/ParseTests.swift +++ b/Tests/RegexTests/ParseTests.swift @@ -3335,6 +3335,13 @@ extension RegexTests { + "a" + String(repeating: ")*", count: 500), .nestingTooDeep) + + diagnosticTest( + String(repeating: "[", count: 500) + + "a" + + String(repeating: "]*", count: 500), + .nestingTooDeep) + } func testDelimiterLexingErrors() {