Skip to content

<string>: wstring::find_first_of crashes on some inputs #5757

@AlexGuteniev

Description

@AlexGuteniev

Describe the bug

When a specific mix of characters in 0-255 range and not in 0-255 range is passed to wstring::find_first_of, it crashes.

Command-line test case

**********************************************************************
** Visual Studio 2026 Developer Command Prompt v18.0.0-insiders
** Copyright (c) 2025 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Program Files\Microsoft Visual Studio\18\Insiders>cd %temp%

C:\Users\ALEXG~1\AppData\Local\Temp>type woof.cpp
#include <string>
#include <iostream>

using namespace std;

int main() {
    wstring hay(200, L'z');
    wstring needle;
    needle.resize(32);

    for (int k = 0; k != 32; k += 16) {
        for (int i = 0; i != 8; ++i) {
            needle[i + k] = 'a' + i;
        }

        for (int i = 8; i != 16; ++i) {
            needle[i + k] = 0xFF00 + i;
        }
    }

    auto pos = hay.find_first_of(needle);
    cout << "Found at:" << pos;
}
C:\Users\ALEXG~1\AppData\Local\Temp>cl woof.cpp /EHsc
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35503 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

woof.cpp
Microsoft (R) Incremental Linker Version 14.50.35503.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:woof.exe
woof.obj

C:\Users\ALEXG~1\AppData\Local\Temp>woof.exe

C:\Users\ALEXG~1\AppData\Local\Temp>echo %errorlevel%
-1073741819

Expected behavior

No crash, print something, %errorlevel% zero

STL version

19.50.35503 for x64

Additional context

Reported internally

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions