View Issue Details

IDProjectCategoryView StatusLast Update
0014921MMW v4Framework: Scripts/Extensionspublic2018-07-09 20:51
Reporterzvezdan Assigned To 
PriorityhighSeverityminorReproducibilityrandom
Status resolvedResolutionunable to reproduce 
Product Version4.0.7 
Target Version4.1.22 
Summary0014921: Untrapable AV error with RegEx
DescriptionI am getting the Access Violation error with the RegExp object that is not trappable with On Error Resume Next. The next RegEx pattern is not quite optimized, in fact it produces the unwanted result, but it should work fine.

The pattern is: ()(\s*)()(?!(?:.*? - ){2,}).*?( - )(\s*)(?=(?:.*? - ){1})
The replacement is: $1$2$3$5
The test string is: A - B - C - D - E

It is tested on several on-line RegEx testers and nowhere produced any problem, it is not making browser unresponsive or anything like that:
https://regexr.com/
https://regex101.com/#javascript
http://rextester.com/replace

I believe that you are doing something wrong with RegEx engine in your program which also caused the recent problem with Windows Defender and my another scripts that use extensively the MatchCollection object during startup, as I described in the related Issue (https://www.ventismedia.com/mantis/view.php?id=14820#c50347).
Steps To ReproduceHere is the test VBScript which could be started directly from the command line, it doesn't produce any error or any similar problem:

Option Explicit
Dim oRegEx
Set oRegEx = New RegExp
oRegEx.IgnoreCase = True
oRegEx.Global = True
oRegEx.Multiline = False
oRegEx.Pattern = "()(\s*)()(?!(?:.*? - ){2,}).*?( - )(\s*)(?=(?:.*? - ){1})"
MsgBox oRegEx.Replace("A - B - C - D - E", "$1$2$3$5")

Now, here is the MM test script which produces the mentioned AV error followed with another message box saying "Variant or safe array is locked", but it does not happen always. I cannot find out how to reproduce it reliably, it seems that it depends of what files are displayed in the filelist and/or Now Playing panel:

Option Explicit

Sub OnStartUp()
    Dim oMenuItem

    Set oMenuItem = SDB.UI.AddMenuItem(SDB.UI.Menu_File, 0, 0)
    oMenuItem.Caption = "RegEx test"
    oMenuItem.OnClickFunc = "Test"
    oMenuItem.UseScript = Script.ScriptPath
End Sub

Sub Test(oMenuItem)
    Dim oRegEx
    Dim sTmp

    Set oRegEx = New RegExp
    oRegEx.IgnoreCase = True
    oRegEx.Global = True
    oRegEx.Multiline = False

    On Error Resume Next
    oRegEx.Pattern = "()(\s*)()(?!(?:.*? \- ){2,}).*?( \- )(\s*)(?=(?:.*? \- ){1})"
    sTmp = oRegEx.Replace("A - B - C - D - E", "$1$2$3$5")
    SDB.MessageBox sTmp, mtInformation, Array(mbOk)
    On Error GoTo 0
End Sub

Note the On Error Resume Next line which has no effect in this case.
TagsNo tags attached.
Fixed in build

Activities

Ludek

2018-07-09 16:16

developer   ~0050728

http://www.mediamonkey.com/forum/viewtopic.php?f=1&t=90485&e=1&view=unread#p447221

Ludek

2018-07-09 19:17

developer   ~0050730

Last edited: 2018-07-09 20:51

RegEx is not our object, it is VBScript's object -- so I don't see how we could affect this by our application.

I cannot replicate any AV with the testing script.
The script is just taking result of RegEx.Replace (which is string) and shows the string using our SDB.MessageBox