Skip to content

Misc. bug: Lazy grammar constructor seg fault on MacOS #17047

@marek-hradil

Description

@marek-hradil

Name and Version

version: 6964 (22c8c3c)
built with Apple clang version 17.0.0 (clang-1700.0.13.5) for arm64-apple-darwin24.6.0

Operating systems

Mac

Which llama.cpp modules do you know to be affected?

libllama (core library)

Command line

Problem description & steps to reproduce

Constructing a lazy grammar with llama_sampler_init_grammar_lazy, passing non-empty trigger words vector, yields a seg. fault on MacOS. Interestingly this does not seem to happen on linux.

To my knowledge, this is caused by a dangling pointer, in llama_sampler_init_grammar_impl, where stop words are converted to a pattern. On line 1640 in llama-sampling.cpp, trigger_pattern_c pointer is constructed, and assigned to trigger_patterns variable, but trigger_pattern_c then goes out of scope.

I'll draft the pull request with the fix.

First Bad Commit

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions