Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: panic on too many composites #10316

Closed
mattyb opened this issue Apr 2, 2015 · 1 comment
Closed

regexp: panic on too many composites #10316

mattyb opened this issue Apr 2, 2015 · 1 comment
Milestone

Comments

@mattyb
Copy link
Contributor

@mattyb mattyb commented Apr 2, 2015

The code below passes on 1.4.2. On tip (devel +52c84c3), the short test passes but the long test results in a panic.

cc @michaelmatloob

backtrace

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x8 pc=0x57e0a]

goroutine 5 [running]:
testing.tRunner.func1(0x208336000)
    /Users/mbrennan/.gimme/versions/go/src/testing/testing.go:446 +0x174
regexp.(*bitState).reset(0x0, 0x13, 0x4, 0x4)
    /Users/mbrennan/.gimme/versions/go/src/regexp/backtrack.go:70 +0x2a
regexp.(*machine).backtrack(0x2082b4ea0, 0x22084693e8, 0x2082b4f78, 0x0, 0x13, 0x4, 0x20835b6c0)
    /Users/mbrennan/.gimme/versions/go/src/regexp/backtrack.go:314 +0x117
regexp.(*Regexp).doExecute(0x208326320, 0x0, 0x0, 0x0, 0x0, 0x0, 0x197510, 0x13, 0x0, 0x4, ...)
    /Users/mbrennan/.gimme/versions/go/src/regexp/exec.go:449 +0x413
regexp.(*Regexp).FindStringSubmatch(0x208326320, 0x197510, 0x13, 0x0, 0x0, 0x0)
    /Users/mbrennan/.gimme/versions/go/src/regexp/regexp.go:883 +0x9a
command-line-arguments.TestMustCompile(0x208336000)
    /Users/mbrennan/civis/gocode/src/github.com/civisanalytics/regex_fail/regexp_test.go:23 +0x525
testing.tRunner(0x208336000, 0x24f330)
    /Users/mbrennan/.gimme/versions/go/src/testing/testing.go:452 +0xae
created by testing.RunTests
    /Users/mbrennan/.gimme/versions/go/src/testing/testing.go:560 +0xa4b

code

package main

import (
    "regexp"
    "testing"
)

var shortRegex, longRegex *regexp.Regexp

func TestMustCompile(t *testing.T) {
    testString := "100 SESAME ST APT 1"
    shortRegex = regexp.MustCompile(`(ST|STREET|ALLEY|ANNEX|ARCADE|BEND|BOULEVARD|ALY|ANX|ARC|AVE|BYU|BCH|BND|BLVD|BYPASS|BYP|CAUSEWAY|CSWY|CIRCLE|CIR|CIRCLES|CIRS|CORNER|COR|COURT|CT|COURTS|CTS|CRESCENT|CRES|CREST|CRST|CROSSING|XING|CURVE|CURV|DALE|DL|DRIVE|DR|DRIVES|DRS|ESTATE|EST|ESTATES|ESTS|EXPRESSWAY|EXPY|EXTENSION|EXT|EXTENSIONS|EXTS|FORK|FRK|FORKS|FRKS|FREEWAY|FWY|GARDEN|GDN|GARDENS|GDNS|HEIGHTS|HTS|HIGHWAY|HWY|HILL|HL|HILLS|HLS|HOLLOW|HOLW|INLET|INLT|ISLAND|IS|STREETS|STS|SUMMIT|SMT|TERRACE|TER|THROUGHWAY|TRWY|TRACE|TRCE|TRACK|TRAK|TRAFFICWAY|TRFY|TRAIL|TRL|TRAILER|TRLR|TUNNEL|TUNL|TURNPIKE|TPKE|UNDERPASS|UPAS|VALLEY|VLY|VALLEYS|VLYS|VIADUCT|VIA|WALK|WALKS|WAY|WAYS)`)
    longRegex = regexp.MustCompile(`(ST|STREET|ALLEY|ANNEX|ARCADE|BEND|BOULEVARD|ALY|ANX|ARC|AVE|BYU|BCH|BND|BLVD|BYPASS|BYP|CAUSEWAY|CSWY|CIRCLE|CIR|CIRCLES|CIRS|CORNER|COR|COURT|CT|COURTS|CTS|CRESCENT|CRES|CREST|CRST|CROSSING|XING|CURVE|CURV|DALE|DL|DRIVE|DR|DRIVES|DRS|ESTATE|EST|ESTATES|ESTS|EXPRESSWAY|EXPY|EXTENSION|EXT|EXTENSIONS|EXTS|FORK|FRK|FORKS|FRKS|FREEWAY|FWY|GARDEN|GDN|GARDENS|GDNS|HEIGHTS|HTS|HIGHWAY|HWY|HILL|HL|HILLS|HLS|HOLLOW|HOLW|INLET|INLT|ISLAND|IS|STREETS|STS|SUMMIT|SMT|TERRACE|TER|THROUGHWAY|TRWY|TRACE|TRCE|TRACK|TRAK|TRAFFICWAY|TRFY|TRAIL|TRL|TRAILER|TRLR|TUNNEL|TUNL|TURNPIKE|TPKE|UNDERPASS|UPAS|VALLEY|VLY|VALLEYS|VLYS|VIADUCT|VIA|WALK|WALKS|WAY|WAYS|BREAKAGE)`)
    t.Logf("short regex string: %s", shortRegex.String())
    t.Logf("long regex string: %s", longRegex.String())
    shortMatches := shortRegex.FindStringSubmatch(testString)
    t.Logf("%+v", shortMatches)
    if shortMatches[0] != "ST" {
        t.Errorf("short regex failed")
    } else {
        t.Logf("short regex passed")
    }
    longMatches := longRegex.FindStringSubmatch(testString)
    t.Logf("%+v", longMatches)
    if longMatches[0] != "ST" {
        t.Errorf("long regex failed")
    } else {
        t.Logf("long regex passed")
    }
}
@mattyb mattyb changed the title regexp: crash on too many composites regexp: panic on too many composites Apr 2, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.5 milestone Apr 2, 2015
@mattyb
Copy link
Contributor Author

@mattyb mattyb commented Apr 9, 2015

Fixed with a513088

@mattyb mattyb closed this Apr 9, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.