The invention provides a structured
annotation enhanced
vulnerability detection method based on dynamic path selection, and belongs to the field of
source code vulnerability detection. Comprising the steps that 1, each
code snippet is analyzed into an
abstract syntax tree, and a corresponding
control flow graph is constructed; 2, evaluating the importance of paths in the
control flow diagram, and dynamically selecting a plurality of paths; 3, the code snippets are provided for the large
language model, corresponding row-level annotations are generated for each row of codes, and the annotations are inserted into a selected path according to a predefined
annotation insertion rule; and step 4, coding the
annotation paths into vectors, extracting a local dependency relationship between the paths, modeling a global dependency relationship between the paths, and finally performing
vulnerability detection based on fusion features. According to the model provided by the invention, a code structure and a vulnerability situation can be comprehensively understood, and more efficient and more accurate
vulnerability detection is realized.