A defect function positioning method based on semantic dependency screening and contrast learning

By employing a method based on semantic dependency filtering and contrastive learning, and utilizing a large model for dependency semantic anchoring and causal chain alignment, the defect function localization problem in cross-modal semantic alignment is solved, achieving high-precision and high-reliability defect function localization.

CN122065319BActive Publication Date: 2026-07-21JIANGXI NORMAL UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
JIANGXI NORMAL UNIV
Filing Date
2026-04-20
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing technologies lack dependency semantic mining, causal anchor point establishment, and feature discrimination in cross-modal semantic alignment, resulting in low accuracy in defect function localization, inability to effectively lock risk functions, and low quality of negative samples, leading to a high false positive rate.

Method used

We adopt a semantic dependency filtering and contrastive learning approach. Through a new semantic alignment paradigm centered on dependencies, we use a large model to perform semantic anchoring of dependencies and causal chain alignment, construct difficult negative samples, and improve the accuracy and reliability of defect function localization.

Benefits of technology

It effectively breaks through the bottleneck of cross-modal correlation, improves the accuracy and reliability of defect function localization, reduces path explosion and multi-language adaptation problems, and enhances the accuracy of localization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122065319B_ABST
    Figure CN122065319B_ABST
Patent Text Reader

Abstract

The application relates to the fields of natural language processing and software security, and discloses a defect function positioning method based on semantic dependency screening and contrast learning, which comprises the following steps: acquiring defect description texts and performing structural analysis to obtain four-tuple vectors; performing high-confidence candidate function screening according to the four-tuple vectors and source code data to obtain a high-confidence candidate function subset; and performing defect function positioning on the high-confidence candidate function subset to output a final defect function result. The application breaks through the bottleneck of cross-modal correlation by proposing a new semantic alignment paradigm with dependency items as the core pivot and using a large model to perform semantic anchoring and causal chain alignment on the dependency items, significantly improves the reliability of defect function positioning, and effectively alleviates the path explosion and multilingual adaptation problems faced by traditional methods. The application avoids the bottleneck limitation of cross-modal correlation, and improves the accuracy and reliability of defect function positioning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of natural language processing and software security, and in particular to a defect function localization method based on semantic dependency filtering and contrastive learning. Background Technology

[0002] In today's increasingly complex software supply chain, the rate at which software security vulnerabilities are disclosed far exceeds the response capacity of manual remediation, posing a severe challenge to software security protection. The CVE (Common Vulnerabilities and Exposures) and NVD (National Vulnerability Database) public vulnerability databases add hundreds of detailed defect descriptions daily, while the corresponding multi-language mixed code repositories contain millions of lines of code. This information gap makes vulnerability localization a core bottleneck in the field of software security. Against this backdrop, how to directly and accurately map vulnerability descriptions in natural language to specific defective functions in the source code has become a critical scientific and technical challenge that urgently needs to be overcome in the field of software security. Vulnerability localization is essentially a typical cross-modal semantic alignment problem. The core difficulty stems from the essential differences between the two sets of data: vulnerability description text is unstructured and contains numerous implicit domain knowledge contextual assumptions, while the target source code is highly structured with complex dependencies between functions. Significant differences exist in vocabulary distribution, grammatical form, and information density, resulting in limited accuracy of existing localization methods and making it difficult to meet the needs of engineering practice.

[0003] To alleviate the aforementioned cross-modal semantic gap, researchers have gradually introduced deep learning techniques to construct localization models in recent years. However, related research still suffers from three major shortcomings: First, insufficient semantic value mining of "dependencies." Existing studies often treat dependencies in code as ordinary tokens, ignoring the core principle that vulnerability triggering is often directly related to the misuse of specific APIs and the lack of defensive dependencies. This makes it impossible to accurately pinpoint risk functions through dependency differences, resulting in high redundancy in the initial candidate set and a surge in subsequent computational costs. Second, cross-modal semantic alignment lacks "causal anchors," relying solely on surface feature matching between text and code. It fails to establish a causal relationship between the "vulnerability cause and attack medium" in the defect description and the code logic. When the defect description is ambiguous or the code structure is complex, semantic mismatches are prone to occur, leading to a large number of false positives. Third, insufficient feature discrimination and low-quality negative samples. Existing methods often use simple data to construct negative samples without considering the semantic equivalence at the code syntax level. This makes it difficult for the model to distinguish functions that are "superficially different but semantically consistent," resulting in a significant decrease in localization accuracy in similar function sets. At the same time, traditional contrastive learning loss functions cannot effectively strengthen the weights of causally related features, further restricting localization performance.

[0004] Therefore, designing a defect function localization method that avoids the bottleneck limitations of cross-modal correlation and improves the accuracy and reliability of localization has become an urgent problem to be solved. Summary of the Invention

[0005] Based on this, this invention proposes a defect function localization method based on semantic dependency filtering and contrastive learning. By moving away from the design approach of directly matching vulnerability descriptions and code, it proposes a new semantic alignment paradigm with dependencies as the core hub. It utilizes a large model for semantic anchoring of dependencies and causal chain alignment, effectively overcoming the bottleneck of cross-modal association. By constructing difficult negative samples with adversarial learning, it significantly improves the reliability of defect function localization and effectively alleviates the path explosion and multilingual adaptation problems faced by traditional methods. This invention avoids the bottleneck limitations of cross-modal association and improves the accuracy and reliability of defect function localization.

[0006] This invention proposes a defect function localization method based on semantic dependency filtering and contrastive learning, comprising: Defect description text is obtained and structured parsed to obtain a quadruple vector. The structured parsing is based on a standardized extraction template and a code-text cross-modal encoder. High-confidence candidate functions are selected based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions. The selection of high-confidence candidate functions is based on dependency scattering, context-aware program slicing, and causal alignment of thought chains. Defect function localization is performed on the high-confidence candidate function subset to output the final defect function result. The defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking, and contrastive learning.

[0007] In summary, based on the aforementioned defect function localization method using semantic dependency filtering and contrastive learning, this invention moves beyond the design approach of directly matching vulnerability descriptions and code. It proposes a new semantic alignment paradigm centered on dependencies, utilizing a large model for semantic anchoring of dependencies and causal chain alignment. This effectively overcomes the bottleneck of cross-modal association and significantly improves the reliability of defect function localization by constructing challenging negative samples through adversarial learning. This invention effectively alleviates the path explosion and multilingual adaptation problems faced by traditional methods. Furthermore, it avoids the bottleneck limitations of cross-modal association and improves the accuracy and reliability of defect function localization. Specifically, the method involves acquiring defect description text and performing structured parsing to obtain quadruple vectors. This structured parsing is based on standardized extraction templates and a code-text cross-modal encoder. A unified semantic benchmark is generated through structured parsing of the defect description text. High-confidence candidate functions are then selected based on the quadruple vectors and source code data to obtain a subset of high-confidence candidate functions. This selection is based on dependency scattering, context-aware program slicing, and causal alignment of thought chains, accurately identifying high-confidence candidate functions from a massive dataset. A large model is used for dependency semantic anchoring and causal chain alignment, effectively overcoming the bottleneck of cross-modal association. Defect function localization is then performed on the subset of high-confidence candidate functions to output the final defect function result. This defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking, and contrastive learning. Adversarial learning is used to construct difficult negative samples, significantly improving the reliability of defect function localization and effectively alleviating the path explosion and multilingual adaptation problems faced by traditional methods. This invention avoids the bottleneck limitations of cross-modal association and improves the accuracy and reliability of defect function localization.

[0008] Furthermore, the step of obtaining the defect description text and performing structured parsing to obtain a quadruple vector specifically includes: The defect description text is denoised. The denoising process removes redundant modifying statements, performs sentence segmentation, and removes special characters to obtain the core description plain text. The core description plain text is based on the core description of the vulnerability scenario, scope of impact, and triggering conditions. A standardized extraction template is built based on core dimensions, including attack type, attack medium, scope of impact, and cause of vulnerability. The core expression plain text is embedded into a standardized extraction template to output structured text based on the large model; The core dimensions of the structured text are encoded into 768-dimensional semantic vectors using a pre-trained code-text cross-modal encoder, which are then concatenated to form a quadruplet vector.

[0009] Furthermore, the step of filtering high-confidence candidate functions based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions specifically includes: Perform a full abstract syntax tree parsing on the source code data to locate all function call nodes; The specific algorithm for constructing a function-level real dependency graph is as follows: G_real=(F, D_used), Where G_real represents the real dependency graph, F represents the set of all functions, and D_used represents the set of APIs and libraries actually called inside each function; Retrieve the historical patch set of fixed vulnerabilities. The historical patch set of fixed vulnerabilities is the same as the general defect list category of the defect description text. Extract the newly added defensive APIs in the patch code and count the occurrence frequency of all the defensive APIs. Divide the defensive APIs with an occurrence frequency greater than or equal to a preset frequency threshold into the minimum ideal defensive API set. Traverse all functions in the real dependency graph to obtain the set of missing dependencies. The specific algorithm for obtaining the set of missing dependencies is as follows: ΔD = D_safe - D_used(f), Where ΔD represents the set of missing dependencies, D_safe represents the set of minimum ideal defense APIs, D_used represents the set of APIs and libraries actually called inside each function, and f represents all functions in the real dependency graph; The missing dependency set is encoded into a missing dependency vector. The backscatter correlation between the missing dependency vector and the quadruplet vector is calculated. When the backscatter correlation is greater than or equal to a preset backscatter correlation threshold, the code environment of the judgment function has an urgent need for the missing defense API. All functions in the defect description text, the real dependency graph, and the missing dependency set are added to the risk function set. Context-aware program slicing is performed based on the set of risk functions to generate minimal causal slices; Structured text and minimal causal slices are input into a large model to generate thought chain text, and causal confidence is calculated to filter high-confidence candidate functions.

[0010] Furthermore, the step of performing context-aware program slicing based on the risk function set to generate the minimum causal slice specifically includes: Based on named entity recognition, entity words representing attack vectors and vulnerability causes are extracted from the quadruples and mapped to specific variables and key statements within all functions in the real dependency graph to construct a context-aware program slicing criterion. The specific algorithm for the context-aware program slicing criterion is as follows: , in, This indicates the context-aware program slicing criteria. Indicates key statements, Indicates a specific variable; Slicing is performed based on the system dependency graph and the context-aware program slicing criteria. The slicing process starts from the context-aware program slicing criteria, performs reverse traversal along the data dependency edges and control dependency edges, and retains the statement nodes that reach the context-aware program slicing criteria to generate the minimum causal slice.

[0011] Furthermore, the step of inputting structured text and minimum causal slices into a large model to generate thought chain text, and calculating causal confidence to screen high-confidence candidate functions specifically includes: Input structured text and minimum causal slices into a large model, and generate thought chain text based on the thought chain reasoning template; The thought chain text is encoded to generate a thought chain vector, and then compared with the four-tuple vector using cosine similarity to calculate the causal confidence score. The specific algorithm for calculating the causal confidence score is as follows: p_causal=σ(cos(V_TVD 4 V_CoT 4 )), Where p_causal represents the causal confidence level, σ represents the activation function, and V_TVD 4 V_CoT represents a quadruplet vector. 4 Represents the thought chain vector; Functions with causal confidence levels greater than or equal to a pre-set confidence threshold are classified into a set of high-confidence candidate functions.

[0012] Furthermore, the step of locating defect functions in the subset of high-confidence candidate functions to output the final defect function result specifically includes: All functions are subjected to a three-layer conservative transformation to generate semantically equivalent adversarial functions. The three-layer conservative transformation includes local variable renaming, official API alias replacement, and control flow equivalent rewriting. Generate the full abstract syntax tree path of all functions and semantically equivalent adversarial functions, sample key nodes according to control flow weights for masking, and encode to obtain mask vectors. The key nodes include loop nodes and branch nodes. Construct positive sample pairs and hard negative sample pairs. The positive sample pairs are based on quadruple vectors and all function vectors, and the hard negative sample pairs are based on quadruple vectors and mask vectors. Defect function localization is performed based on positive sample pairs and difficult negative sample pairs.

[0013] Furthermore, the step of locating the defect function based on positive sample pairs and difficult negative sample pairs specifically includes: Vector sample pairs are generated based on the defect description text and all high-confidence candidate functions to calculate cosine similarity. All functions are sorted in descending order of similarity. It is determined whether the highest similarity of the current function is greater than or equal to the preset confidence threshold. If the highest similarity of the current function is greater than or equal to the preset confidence threshold, the current function is determined to be a defective function. If the highest similarity of the current function is less than the preset confidence threshold, it is determined that there is no matching defective function.

[0014] This invention proposes a defect function localization system based on semantic dependency filtering and contrastive learning, comprising: The structured parsing module is used to obtain the defect description text and perform structured parsing to obtain a four-tuple vector. The structured parsing is based on a standardized extraction template and a code-text cross-modal encoder. The function filtering module is used to filter high-confidence candidate functions based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions. The high-confidence candidate function filtering is based on dependency scattering, context-aware program slicing, and causal alignment of thought chains. The defect function localization module is used to locate defect functions in the subset of high-confidence candidate functions to output the final defect function result. The defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking, and contrastive learning.

[0015] The present invention also provides a storage medium that stores one or more programs, which, when executed by a processor, implement the defect function localization method based on semantic dependency filtering and contrastive learning as described above.

[0016] The present invention also provides a computer device, the computer device including a memory and a processor, wherein: The memory is used to store computer programs; When the processor executes the computer program stored in the memory, it implements the defect function localization method based on semantic dependency filtering and contrastive learning as described above. Attached Figure Description

[0017] Figure 1 This is a flowchart of the defect function localization method based on semantic dependency filtering and contrastive learning proposed in the first embodiment of the present invention; Figure 2 This is a schematic diagram of the defect function localization system based on semantic dependency filtering and contrastive learning proposed in the second embodiment of the present invention.

[0018] The following detailed description, in conjunction with the accompanying drawings, will further illustrate the present invention. Detailed Implementation

[0019] To facilitate understanding of the present invention, a more complete description will be given below with reference to the accompanying drawings. Several embodiments of the invention are illustrated in the drawings. However, the invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.

[0020] It should be noted that when a component is said to be "fixed to" another component, it can be directly on the other component or there may be an intervening component. When a component is said to be "connected to" another component, it can be directly connected to the other component or there may be an intervening component. The terms "vertical," "horizontal," "left," "right," and similar expressions used in this document are for illustrative purposes only.

[0021] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.

[0022] Please see Figure 1 The diagram shows a flowchart of the defect function localization method based on semantic dependency filtering and contrastive learning proposed in the first embodiment of the present invention. This defect function localization method based on semantic dependency filtering and contrastive learning includes steps S01 to S03, wherein: Step S01: Obtain the defect description text and perform structured parsing to obtain a quadruple vector; It should be noted that in this embodiment, the structured parsing is based on a standardized extraction template and a code-text cross-modal encoder to denoise the defect description text. The denoising process removes redundant modifiers, performs sentence segmentation, and removes special characters to obtain the core expression plain text. The core expression plain text is based on the core expression of the vulnerability scenario, scope of impact, and triggering conditions. A standardized extraction template is built based on core dimensions, including attack type, attack medium, scope of impact, and cause of vulnerability. The specific content of the standardized extraction template in this embodiment includes: extracting attack type, attack medium, scope of impact, and cause of vulnerability from text [X], in the format [dimension]: content; The core expression plain text is embedded into a standardized extraction template to output structured text based on the large model; The core dimensions of the structured text are encoded into 768-dimensional semantic vectors using a pre-trained code-text cross-modal encoder, which are then concatenated to form a quadruplet vector.

[0023] Step S02: Filter high-confidence candidate functions based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions; It should be noted that in this embodiment, the high-confidence candidate function screening is based on dependency scattering, context-aware program slicing, and causal alignment of thought chains, and performs full abstract syntax tree parsing on the source code data to locate all function call nodes; The specific algorithm for constructing a function-level real dependency graph is as follows: G_real=(F, D_used), Where G_real represents the real dependency graph, F represents the set of all functions, and D_used represents the set of APIs and libraries actually called inside each function; Retrieve the historical patch set of fixed vulnerabilities. The historical patch set of fixed vulnerabilities is the same as the general defect list category of the defect description text. Extract the newly added defensive APIs in the patch code and count the occurrence frequency of all the defensive APIs. Divide the defensive APIs with an occurrence frequency greater than or equal to a preset frequency threshold into the minimum ideal defensive API set. The preset frequency threshold in this embodiment is 30%; Traverse all functions in the real dependency graph to obtain the set of missing dependencies. The specific algorithm for obtaining the set of missing dependencies is as follows: ΔD = D_safe - D_used(f), Where ΔD represents the set of missing dependencies, D_safe represents the set of minimum ideal defense APIs, D_used represents the set of APIs and libraries actually called inside each function, and f represents all functions in the real dependency graph; The missing dependency set is encoded into a missing dependency vector. The backscatter correlation between the missing dependency vector and the quadruplet vector is calculated. When the backscatter correlation is greater than or equal to a preset backscatter correlation threshold, the code environment of the judgment function has an urgent need for the missing defense API. All functions in the defect description text, the real dependency graph, and the missing dependency set are added to the risk function set. In this embodiment, the preset backscatter correlation threshold is 0.65; Context-aware program slicing is performed based on the set of risk functions to generate minimal causal slices; Structured text and minimal causal slices are input into a large model to generate thought chain text, and causal confidence is calculated to filter high-confidence candidate functions.

[0024] Based on named entity recognition, entity words representing attack vectors and vulnerability causes are extracted from the quadruples and mapped to specific variables and key statements within all functions in the real dependency graph to construct a context-aware program slicing criterion. The specific algorithm for the context-aware program slicing criterion is as follows: , in, This indicates the context-aware program slicing criteria. Indicates key statements, Indicates a specific variable; Slicing is performed based on the system dependency graph and the context-aware program slicing criteria. The slicing process starts from the context-aware program slicing criteria, performs reverse traversal along the data dependency edges and control dependency edges, and retains the statement nodes that reach the context-aware program slicing criteria to generate the minimum causal slice.

[0025] Input structured text and minimum causal slices into a large model, and generate thought chain text based on the thought chain reasoning template; The thought chain text is encoded to generate a thought chain vector, and then compared with the four-tuple vector using cosine similarity to calculate the causal confidence score. The specific algorithm for calculating the causal confidence score is as follows: p_causal=σ(cos(V_TVD 4 V_CoT 4 )), Where p_causal represents the causal confidence level, σ represents the activation function, and V_TVD 4 V_CoT represents a quadruplet vector. 4 Represents the thought chain vector; Functions with causal confidence scores greater than or equal to a pre-set confidence threshold are classified into a set of high-confidence candidate functions; In this embodiment, the confidence threshold is preset to 0.8.

[0026] Step S03: Locate the defect function in the high-confidence candidate function subset to output the final defect function result; It should be noted that in this embodiment, the defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking, and contrastive learning. Three-layer conservative transformation is performed on all functions to generate semantically equivalent adversarial functions. The three-layer conservative transformation includes local variable renaming, official API alias replacement, and control flow equivalent rewriting. Generate the full abstract syntax tree path of all functions and semantically equivalent adversarial functions, sample key nodes according to control flow weights for masking, and encode to obtain mask vectors. The key nodes include loop nodes and branch nodes. Construct positive sample pairs and hard negative sample pairs. The positive sample pairs are based on quadruple vectors and all function vectors, and the hard negative sample pairs are based on quadruple vectors and mask vectors. Defect function localization is performed based on positive sample pairs and difficult negative sample pairs.

[0027] Vector sample pairs are generated based on the defect description text and all high-confidence candidate functions to calculate cosine similarity. All functions are sorted in descending order of similarity. It is determined whether the highest similarity of the current function is greater than or equal to the preset confidence threshold. If the highest similarity of the current function is greater than or equal to the preset confidence threshold, the current function is determined to be a defective function. If the highest similarity of the current function is less than the preset confidence threshold, it is determined that there is no matching defective function.

[0028] In summary, based on the aforementioned defect function localization method using semantic dependency filtering and contrastive learning, this invention moves beyond the design approach of directly matching vulnerability descriptions and code. It proposes a new semantic alignment paradigm centered on dependencies, utilizing a large model for semantic anchoring of dependencies and causal chain alignment. This effectively overcomes the bottleneck of cross-modal association and significantly improves the reliability of defect function localization by constructing challenging negative samples through adversarial learning. This invention effectively alleviates the path explosion and multilingual adaptation problems faced by traditional methods. Furthermore, it avoids the bottleneck limitations of cross-modal association and improves the accuracy and reliability of defect function localization. Specifically, the method involves acquiring defect description text and performing structured parsing to obtain quadruple vectors. This structured parsing is based on standardized extraction templates and a code-text cross-modal encoder. A unified semantic benchmark is generated through structured parsing of the defect description text. High-confidence candidate functions are then selected based on the quadruple vectors and source code data to obtain a subset of high-confidence candidate functions. This selection is based on dependency scattering, context-aware program slicing, and causal alignment of thought chains, accurately identifying high-confidence candidate functions from a massive dataset. A large model is used for dependency semantic anchoring and causal chain alignment, effectively overcoming the bottleneck of cross-modal association. Defect function localization is then performed on the subset of high-confidence candidate functions to output the final defect function result. This defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking, and contrastive learning. Adversarial learning is used to construct difficult negative samples, significantly improving the reliability of defect function localization and effectively alleviating the path explosion and multilingual adaptation problems faced by traditional methods. This invention avoids the bottleneck limitations of cross-modal association and improves the accuracy and reliability of defect function localization.

[0029] Please see Figure 2The figure shows a schematic diagram of the defect function localization system based on semantic dependency filtering and contrastive learning proposed in the second embodiment of the present invention. The system includes: The structured parsing module 10 is used to obtain the defect description text and perform structured parsing to obtain a four-tuple vector. The structured parsing is based on a standardized extraction template and a code-text cross-modal encoder. The function filtering module 20 is used to filter high-confidence candidate functions based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions. The high-confidence candidate function filtering is based on dependency scattering, context-aware program slicing, and thought chain causal alignment. The defect function localization module 30 is used to locate the defect function in the subset of high-confidence candidate functions and output the final defect function result. The defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking and contrastive learning.

[0030] The present invention also proposes a computer storage medium storing one or more programs that, when executed by a processor, implement the aforementioned defect function localization method based on semantic dependency filtering and contrastive learning.

[0031] The present invention also proposes a computer device, including a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to realize the above-mentioned defect function localization method based on semantic dependency screening and contrastive learning.

[0032] Those skilled in the art will understand that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can mean any means that can contain stored, communicated, propagated, or transmitted programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.

[0033] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.

[0034] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0035] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0036] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention. Therefore, the scope of protection of this patent should be determined by the appended claims.

Claims

1. A defect function localization method based on semantic dependency filtering and contrastive learning, characterized in that, include: Defect description text is obtained and structured parsed to obtain a quadruple vector. The structured parsing is based on a standardized extraction template and a code-text cross-modal encoder. High-confidence candidate functions are selected based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions. The selection of high-confidence candidate functions is based on dependency scattering, context-aware program slicing, and causal alignment of thought chains. The step of filtering high-confidence candidate functions based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions specifically includes: Perform a full abstract syntax tree parsing on the source code data to locate all function call nodes; The specific algorithm for constructing a function-level real dependency graph is as follows: G_real=(F, D_used), Where G_real represents the real dependency graph, F represents the set of all functions, and D_used represents the set of APIs and libraries actually called inside each function; Retrieve the historical patch set of fixed vulnerabilities. The historical patch set of fixed vulnerabilities is the same as the general defect list category of the defect description text. Extract the newly added defensive APIs in the patch code and count the occurrence frequency of all the defensive APIs. Divide the defensive APIs with an occurrence frequency greater than or equal to a preset frequency threshold into the minimum ideal defensive API set. Traverse all functions in the real dependency graph to obtain the set of missing dependencies. The specific algorithm for obtaining the set of missing dependencies is as follows: ΔD = D_safe - D_used(f), Where ΔD represents the set of missing dependencies, D_safe represents the set of minimum ideal defense APIs, D_used represents the set of APIs and libraries actually called inside each function, and f represents all functions in the real dependency graph; The missing dependency set is encoded into a missing dependency vector. The backscatter correlation between the missing dependency vector and the quadruplet vector is calculated. When the backscatter correlation is greater than or equal to a preset backscatter correlation threshold, the code environment of the judgment function has an urgent need for the missing defense API. All functions in the defect description text, the real dependency graph, and the missing dependency set are added to the risk function set. Context-aware program slicing is performed based on the set of risk functions to generate minimal causal slices; The structured text and the minimum causal slice are input into a large model to generate thought chain text, and the causal confidence is calculated to filter high-confidence candidate functions; The step of performing context-aware program slicing based on the risk function set to generate the minimum causal slice specifically includes: Based on named entity recognition, entity words representing attack vectors and vulnerability causes are extracted from the quadruples and mapped to specific variables and key statements within all functions in the real dependency graph to construct a context-aware program slicing criterion. The specific algorithm for the context-aware program slicing criterion is as follows: , in, This indicates the context-aware program slicing criteria. Indicates key statements, Indicates a specific variable; Slicing is performed based on the system dependency graph and the context-aware program slicing criteria. The slicing process starts from the context-aware program slicing criteria, traverses in reverse along the data dependency edges and control dependency edges, and retains the statement nodes that reach the context-aware program slicing criteria to generate the minimum causal slice. The steps of inputting structured text and minimum causal slices into a large model to generate thought chain text, and calculating causal confidence to screen high-confidence candidate functions, specifically include: Input structured text and minimum causal slices into a large model, and generate thought chain text based on the thought chain reasoning template; The thought chain text is encoded to generate a thought chain vector, and then compared with the four-tuple vector using cosine similarity to calculate the causal confidence score. The specific algorithm for calculating the causal confidence score is as follows: p_causal=σ(cos(V_TVD 4 , V_CoT 4 )), Where p_causal represents the causal confidence level, σ represents the activation function, and V_TVD 4 V_CoT represents a quadruplet vector. 4 Represents the thought chain vector; Functions with causal confidence scores greater than or equal to a pre-set confidence threshold are classified into a set of high-confidence candidate functions; Defect function localization is performed on the high-confidence candidate function subset to output the final defect function result. The defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking, and contrastive learning.

2. The defect function localization method based on semantic dependency filtering and contrastive learning according to claim 1, characterized in that, The step of obtaining the defect description text and performing structured parsing to obtain a four-tuple vector specifically includes: The defect description text is denoised. The denoising process removes redundant modifying statements, performs sentence segmentation, and removes special characters to obtain the core description plain text. The core description plain text is based on the core description of the vulnerability scenario, scope of impact, and triggering conditions. A standardized extraction template is built based on core dimensions, including attack type, attack medium, scope of impact, and cause of vulnerability. The core expression plain text is embedded into a standardized extraction template to output structured text based on the large model; The core dimensions of the structured text are encoded into 768-dimensional semantic vectors using a pre-trained code-text cross-modal encoder, which are then concatenated to form a quadruplet vector.

3. The defect function localization method based on semantic dependency filtering and contrastive learning according to claim 1, characterized in that, The step of locating defect functions in the subset of high-confidence candidate functions to output the final defect function result specifically includes: All functions are subjected to a three-layer conservative transformation to generate semantically equivalent adversarial functions. The three-layer conservative transformation includes local variable renaming, official API alias replacement, and control flow equivalent rewriting. Generate the full abstract syntax tree path of all functions and semantically equivalent adversarial functions, sample key nodes according to control flow weights for masking, and encode to obtain mask vectors. The key nodes include loop nodes and branch nodes. Construct positive sample pairs and hard negative sample pairs. The positive sample pairs are based on quadruple vectors and all function vectors, and the hard negative sample pairs are based on quadruple vectors and mask vectors. Defect function localization is performed based on positive sample pairs and difficult negative sample pairs.

4. The defect function localization method based on semantic dependency filtering and contrastive learning according to claim 3, characterized in that, The step of locating the defect function based on positive sample pairs and difficult negative sample pairs specifically includes: Vector sample pairs are generated based on the defect description text and all high-confidence candidate functions to calculate cosine similarity. All functions are sorted in descending order of similarity. It is determined whether the highest similarity of the current function is greater than or equal to the preset confidence threshold. If the highest similarity of the current function is greater than or equal to the preset confidence threshold, the current function is determined to be a defective function. If the highest similarity of the current function is less than the preset confidence threshold, it is determined that there is no matching defective function.

5. A defect function localization system based on semantic dependency filtering and contrastive learning, characterized in that, include: The structured parsing module is used to obtain the defect description text and perform structured parsing to obtain a four-tuple vector. The structured parsing is based on a standardized extraction template and a code-text cross-modal encoder. The function filtering module is used to filter high-confidence candidate functions based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions. The high-confidence candidate function filtering is based on dependency scattering, context-aware program slicing, and causal alignment of thought chains. The step of filtering high-confidence candidate functions based on the quadruplet vector and source code data to obtain a subset of high-confidence candidate functions specifically includes: Perform a full abstract syntax tree parsing on the source code data to locate all function call nodes; The specific algorithm for constructing a function-level real dependency graph is as follows: G_real=(F, D_used), Where G_real represents the real dependency graph, F represents the set of all functions, and D_used represents the set of APIs and libraries actually called inside each function; Retrieve the historical patch set of fixed vulnerabilities. The historical patch set of fixed vulnerabilities is the same as the general defect list category of the defect description text. Extract the newly added defensive APIs in the patch code and count the occurrence frequency of all the defensive APIs. Divide the defensive APIs with an occurrence frequency greater than or equal to a preset frequency threshold into the minimum ideal defensive API set. Traverse all functions in the real dependency graph to obtain the set of missing dependencies. The specific algorithm for obtaining the set of missing dependencies is as follows: ΔD = D_safe - D_used(f), Where ΔD represents the set of missing dependencies, D_safe represents the set of minimum ideal defense APIs, D_used represents the set of APIs and libraries actually called inside each function, and f represents all functions in the real dependency graph; The missing dependency set is encoded into a missing dependency vector. The backscatter correlation between the missing dependency vector and the quadruplet vector is calculated. When the backscatter correlation is greater than or equal to a preset backscatter correlation threshold, the code environment of the judgment function has an urgent need for the missing defense API. All functions in the defect description text, the real dependency graph, and the missing dependency set are added to the risk function set. Context-aware program slicing is performed based on the set of risk functions to generate minimal causal slices; The structured text and the minimum causal slice are input into a large model to generate thought chain text, and the causal confidence is calculated to filter high-confidence candidate functions; The step of performing context-aware program slicing based on the risk function set to generate the minimum causal slice specifically includes: Based on named entity recognition, entity words representing attack vectors and vulnerability causes are extracted from the quadruples and mapped to specific variables and key statements within all functions in the real dependency graph to construct a context-aware program slicing criterion. The specific algorithm for the context-aware program slicing criterion is as follows: , in, This indicates the context-aware program slicing criteria. Indicates key statements, Indicates a specific variable; Slicing is performed based on the system dependency graph and the context-aware program slicing criteria. The slicing process starts from the context-aware program slicing criteria, traverses in reverse along the data dependency edges and control dependency edges, and retains the statement nodes that reach the context-aware program slicing criteria to generate the minimum causal slice. The steps of inputting structured text and minimum causal slices into a large model to generate thought chain text, and calculating causal confidence to screen high-confidence candidate functions, specifically include: Input structured text and minimum causal slices into a large model, and generate thought chain text based on the thought chain reasoning template; The thought chain text is encoded to generate a thought chain vector, and then compared with the four-tuple vector using cosine similarity to calculate the causal confidence score. The specific algorithm for calculating the causal confidence score is as follows: p_causal=σ(cos(V_TVD 4 , V_CoT 4 )), Where p_causal represents the causal confidence level, σ represents the activation function, and V_TVD 4 V_CoT represents a quadruplet vector. 4 Represents the thought chain vector; Functions with causal confidence scores greater than or equal to a pre-set confidence threshold are classified into a set of high-confidence candidate functions; The defect function localization module is used to locate defect functions in the subset of high-confidence candidate functions to output the final defect function result. The defect function localization is based on syntactic adversarial transformation, full abstract syntax tree masking, and contrastive learning.

6. A storage medium, characterized in that, The storage medium stores one or more programs, which, when executed by a processor, implement the defect function localization method based on semantic dependency filtering and contrastive learning as described in any one of claims 1-4.

7. A computer device, characterized in that, The computer device includes a memory and a processor, wherein: The memory is used to store computer programs; When the processor executes the computer program stored in the memory, it implements the defect function localization method based on semantic dependency filtering and contrastive learning as described in any one of claims 1-4.