A defect detection method and system based on optimal vertex matching

By using the optimal vertex matching method in code defect detection, noisy vertices are removed and high-order similarity encoding is used to use graph convolutional neural networks to solve the false alarm and missed alarm problems under the influence of noise, and efficient code defect detection is achieved .

CN114998289BActive Publication Date: 2024-12-20RENMIN UNIVERSITY OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210696832.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-20
Publication Date
2024-12-20
Estimated Expiration
2042-06-20

AI Technical Summary

Technical Problem

Existing code defect detection methods are prone to false positives and missed reports when processing noisy statements, and the calculation time overhead of optimal vertex matching is relatively large, making it difficult to effectively apply in large-scale code bases.

Method used

Using the defect detection method of optimal vertex matching, the code feature map is converted into vectors, the noise vertices are removed using BERT model and VME model, the candidate target map is filtered, and the graph convolution neural network and attention mechanism are used to perform higher-order similarity Coding reduces time complexity.

Benefits of technology

It effectively reduces the impact of noise, improves the accuracy and efficiency of defect detection, and can efficiently detect code defects in large-scale code bases, reducing the rate of missed and false alarms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114998289B_ABST
    Figure CN114998289B_ABST
Patent Text Reader

Abstract

The present invention relates to a defect detection method and system with optimal vertex matching, which is characterized by comprising: selecting a function containing a known defect as a seed; parsing the target source code and the seed in the system to be detected into a code feature graph with an intermediate statement as a vertex in a function unit, and purifying the code feature graph of the seed; screening out a target code feature graph with a high matching degree with the purified seed graph as a candidate target graph; encoding the high-order similarity between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph; and determining whether the candidate target graph contains an unknown defect similar to the seed defect according to the similarity between the seed graph and the candidate target graph. The present invention can be widely applied to the field of program safety technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of program security technology, and in particular to an optimal vertex matching defect detection method and system. Background Art

[0002] Code defects may cause logical problems in software systems, resulting in economic losses or system crashes. In more serious cases, they may be exploited by malicious users to constitute security vulnerabilities, posing a huge threat to the information security of individual users, enterprises, institutions and even national governments. Therefore, code defect detection has always been an important research topic. In recent years, defect detection methods based on code similarity measurement have been proven to be very effective. Such methods use code snippets (e.g., functions) containing known defects as seeds and match them with code snippets (targets) in the target library to detect suspicious objects similar to the seeds. Code snippets are essentially a kind of graph, which can be naturally represented as various code graphs, such as control flow graphs and program dependency graphs. Therefore, there have been many studies in the academic community to analyze programs based on graph embedding and detect code defects based on code graph similarity measurement. However, in practice, the logic of a defect usually only involves several statements in the code snippet, while other statements are irrelevant to the defect and can be regarded as noise. If the entire code graph is encoded as a vector, the information of the noise statement will also be encoded into the graph vector. Therefore, the code similarity measurement task will be seriously disturbed by the noise statement and lead to false positives and false negatives.

[0003] One way to solve the noise problem is to remove the noisy vertices before embedding and matching. The noise in the seed graph can be easily removed because it is possible to identify and determine in advance which statements in the seed code are defect-related. For example, some studies apply slicing methods to remove noise in seed functions. However, it is not possible to assume that there are specific defects in the target code and mark the relevant statements in advance to exclude noise. In other words, when comparing the target code with the seed code, there will inevitably be noise in the former. When only the noise in the seed is excluded, the similarity measurement will still be disturbed. In essence, the noise problem can be effectively solved by optimal vertex matching, that is, if each vertex is optimally paired, the vertex corresponding to the sliced ​​seed (purified seed graph) can be located and identified from the target graph. Based on these paired vertices, the similarity between codes can be accurately measured. It is also possible to measure the similarity of the graph based on the vertices of interest, that is, the defect-related vertices in the seed and their corresponding vertices in the target graph, thereby excluding the noise vertices and obtaining a reasonable similarity.

[0004] However, the calculation of optimal vertex matching incurs a huge time overhead. In order to obtain the structural information of the graph, the optimal vertex matching needs to consider the first-order and second-order (or even higher-order) similarities between the vertices of two different graphs at the same time, and maximize the similarity between the matched vertices. Since this task needs to consider high-order similarities, this task is usually NP (polynomial non-deterministic problem) complete. In the practice of code defect detection, it is usually necessary to match seeds with hundreds of thousands of targets, and the total time cost is unacceptable. Therefore, how to accelerate the optimal vertex matching to measure the similarity of code graphs on a large scale and solve the false positives and negatives that may be caused by noise statements in functions containing vulnerabilities in existing work is a technical problem that needs to be solved urgently. Summary of the invention

[0005] In view of the above problems, the purpose of the present invention is to provide a defect detection method and system with optimal vertex matching, which can solve the problems of false positives and false negatives that may be caused by noise statements in functions containing vulnerabilities in existing work.

[0006] To achieve the above objectives, the present invention adopts the following technical solutions: In a first aspect, a defect detection method for optimal vertex matching is provided, comprising:

[0007] Select a function that contains a known defect as a seed;

[0008] Taking functions as units, the target source code and seeds in the system to be tested are parsed into code feature graphs with intermediate statements as vertices, and the code feature graphs of the seeds are purified;

[0009] Filter out the target code feature graphs that have a high matching degree with the purified seed graph as candidate target graphs;

[0010] Encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph;

[0011] According to the similarity between the seed graph and the candidate target graph, it is determined whether the candidate target graph contains unknown defects similar to the seed defect.

[0012] Furthermore, the target source code and the seed in the system to be detected are parsed into a code feature graph with the intermediate statement as the vertex in the function unit, including:

[0013] Taking functions as units, the target source code and seeds in the system to be tested are parsed respectively to obtain the control flow graph and program dependency graph corresponding to each function;

[0014] Combining the control flow graph and program dependency graph of each function, a code feature graph with the intermediate statements as vertices is generated;

[0015] Treat each intermediate sentence as a symbol and the symbol sequence in each function as a sentence, build a corpus, and train the BERT model based on the masked language model;

[0016] Using the BERT model, each symbol is embedded into a vector. If a vertex in the code feature graph contains only one symbol, the vertex vector is a symbol vector. Otherwise, the symbols in the vertex are connected into a phrase, and the BERT model is used to generate a phrase vector. Each function is converted into a code feature graph with vectors as vertices.

[0017] The vertices irrelevant to the defects in the seed code feature graph are removed to obtain the purified seed graph.

[0018] Further, the method of selecting the target code feature graph having a high matching degree with the seed graph as a candidate target graph using the VME model includes:

[0019] The purified seed graph and target graph are input into the VME model, and the purified seed graph and target graph are embedded into the seed vector and target vector respectively;

[0020] Using the VME model, the matching score between the seed vector and the target vector is calculated;

[0021] According to the obtained matching scores, all target images to be detected are sorted in descending order, and the target images with the highest rankings are selected as candidate target images.

[0022] Further, the VME model includes a vertex-oriented matching embedding module and a matching score calculation module, wherein the vertex-oriented matching embedding module includes a multi-layer perceptron network with a gate structure and a maximum pooling layer;

[0023] A multi-layer perceptron network with a gate structure is used to convert the purified seed graph and target graph into vertex vectors respectively;

[0024] The maximum pooling layer is used to aggregate the vertex vectors of the seed graph and the target graph into the whole graph vector respectively;

[0025] The matching score calculation module is used to identify the dimensions in the whole image vector of the seed image that are greater than a certain threshold, extract the dimensions in the whole image vector of the seed image and the target image respectively, and construct the seed vector and the target vector.

[0026] Furthermore, encoding the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph includes:

[0027] The optimal vertex matching model is used to encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the affinity matrix;

[0028] Normalizing the obtained affinity matrix to obtain a normalized affinity matrix;

[0029] According to the normalized affinity matrix, the vertex matching results between the seed graph and the candidate target graph are obtained;

[0030] Based on the obtained vertex matching results, the similarity between the seed graph and the candidate target graph is calculated.

[0031] Furthermore, the optimal vertex matching model includes:

[0032] The seed graph convolution module is used to encode the structural information of the seed graph into the vertex vector to obtain a seed graph with vectors as vertices;

[0033] The target graph convolution module is used to encode the structural information of the candidate target graph into the vertex vector to obtain the candidate target graph with the vector as the vertex;

[0034] The affinity measurement function module is used to input the outputs of the seed graph convolution module and the target graph convolution module into the affinity measurement function to obtain an affinity matrix.

[0035] Furthermore, the determining, based on the similarity between the seed graph and the candidate target graph, whether the candidate target graph contains an unknown defect similar to the seed defect comprises:

[0036] The similarities between the seed map and the candidate target map are averaged and used as the similarity between the candidate target map and the seed map;

[0037] According to the similarity, the functions corresponding to the candidate target graphs are sorted in descending order, and the source codes of the functions corresponding to the candidate target graphs with the highest rankings are analyzed to confirm whether they contain unknown defects similar to the seed defects.

[0038] In a second aspect, a defect detection system for optimal vertex matching is provided, comprising:

[0039] The seed selection module is used to select a function containing known defects as a seed;

[0040] The data preprocessing module is used to parse the target source code and seeds in the system to be detected into code feature graphs with intermediate statements as vertices based on functions, and purify the code feature graphs of the seeds;

[0041] A screening module is used to screen out target code feature graphs that have a high degree of match with the purified seed graph as candidate target graphs;

[0042] A similarity encoding module is used to encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph;

[0043] The defect retrieval module is used to determine whether the candidate target graph contains unknown defects similar to the seed defect based on the similarity between the seed graph and the candidate target graph.

[0044] According to a third aspect, a processing device is provided, comprising computer program instructions, wherein the computer program instructions, when executed by the processing device, are used to implement the steps corresponding to the above-mentioned optimal vertex matching defect detection system method.

[0045] In a fourth aspect, a computer-readable storage medium is provided, on which computer program instructions are stored, wherein the computer program instructions, when executed by a processor, are used to implement the steps corresponding to the above-mentioned optimal vertex matching defect detection system method.

[0046] The present invention adopts the above technical solution, which has the following advantages:

[0047] 1. The present invention removes noise statements irrelevant to defects in the seed code snippet, and measures the similarity between the target code snippet and the seed code snippet based on the optimal vertex matching, thereby suppressing the influence of the noise code, reducing missed reports and false positives in defect detection, and ensuring the efficiency and scalability of detection efficiency.

[0048] 2. The present invention designs an optimal vertex matching model based on graph convolutional neural network, and adds an attention mechanism based on seed graph to it, which can suppress the noise propagation in the target graph and obtain approximate but sufficiently accurate optimal vertex matching results to meet the efficiency requirements of code defect detection.

[0049] 3. The present invention adopts a two-stage strategy to accelerate the optimal vertex matching to avoid solving the NP-complete problem, that is, first quickly filter out the target graph that may have a high matching rate with the seed graph as a candidate, and then calculate the optimal vertex matching result between the candidate target graph and the seed graph based on the HSE model. The present invention adopts two embedding models to obtain approximate but sufficiently accurate optimal vertex matching results, so that the present invention can be applied to large-scale target code libraries.

[0050] In summary, the present invention can be widely used in the fields of code defect detection, program security, etc. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Throughout the accompanying drawings, the same reference numerals are used to represent the same components. In the accompanying drawings:

[0052] Figure 1 It is a schematic diagram of a method flow provided by an embodiment of the present invention;

[0053] Figure 2 It is a schematic diagram of the system structure provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0054] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.

[0055] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.

[0056] Although the terms first, second, third, etc. can be used in the text to describe multiple elements, components, regions, layers and / or sections, these elements, components, regions, layers and / or sections should not be limited by these terms. These terms can only be used to distinguish an element, component, region, layer or section from another region, layer or section. Unless the context clearly indicates, terms such as "first", "second" and other numerical terms do not imply order or sequence when used in the text. Therefore, the first element, component, region, layer or section discussed below can be referred to as the second element, component, region, layer or section without departing from the teaching of the example embodiments.

[0057] In order to solve the problems of false positives and negative alerts that may be caused by noise statements in functions containing vulnerabilities in existing work, the optimal vertex matching defect detection method and system provided in the embodiments of the present invention can suppress the adverse effects of noise statements in the code that are not related to the defects on the code similarity measurement, reduce the negative alerts and false positives of defects, and have higher detection efficiency and scalability compared to the existing defect detection methods based on code similarity.

[0058] Example 1

[0059] like Figure 1 As shown, this embodiment provides a defect detection method for optimal vertex matching, comprising the following steps:

[0060] 1) Select a function containing a known defect as a seed.

[0061] 2) Taking the function as the unit, the target source code and the seed in the system to be detected are parsed into a code feature graph with the intermediate statement as the vertex, and the vertices of the code feature graph are embedded as vectors to represent the function as a code feature graph with the vector as the vertex, and the code feature graph of the seed is purified, specifically:

[0062] 2.1) Taking functions as units, the target source code and seeds in the system to be tested are parsed separately to obtain the control flow graph (CFG) and program dependency graph (PDG) corresponding to each function.

[0063] 2.2) Integrate the control flow graph and program dependency graph of each function (including the function in step 1)) to generate a code feature graph with the intermediate statements as vertices.

[0064] Specifically, the edges of the generated code feature graph include control flow edges, control dependency edges and data dependency edges. The vertices of the code feature graph are several intermediate statements, and the intermediate statement contained in each vertex corresponds to a line of statements in the target source code.

[0065] 2.3) Treat each intermediate sentence as a token and the sequence of symbols in each function as a sentence, build a corpus, and train the BERT model (Bidirectional Encoder Representation from Transformers) based on the masked language model.

[0066] 2.4) Using the BERT model, each symbol (i.e., intermediate sentence) is embedded into a vector. If a vertex in the code feature graph includes only one symbol, the vertex vector is a symbol vector; otherwise, the symbols in the vertex are connected into a phrase, and the BERT model is used to generate a phrase vector. Each function is converted into a code feature graph with vectors as vertices to obtain a seed code feature graph (i.e., seed graph) and a target code feature graph (i.e., target graph).

[0067] 2.5) Remove the vertices in the seed graph that are not related to the defect and obtain the purified seed graph.

[0068] Specifically, based on the public information of known defects (for example, patches), key statements in the function related to the known defects and the key variables therein are marked. Then, a slicing algorithm is used with the key variables as slicing conditions to slice out the defect-related statements in the function according to the program dependency graph corresponding to the function. The vertices corresponding to these related statements will constitute the purified seed graph.

[0069] 3) Using the VME model (Vertex-Matching-oriented Embedding model), the target graphs with high matching degree with the purified seed graph are selected as candidate target graphs, so as to significantly reduce the number of target graphs to be vertex matched. Specifically:

[0070] 3.1) Input the purified seed graph and target graph into the VME model, and embed the purified seed graph and target graph into seed vector and target vector respectively.

[0071] Specifically, the VME model includes a vertex-oriented matching embedding module (VMEmbedding) and a matching score calculation module, wherein the vertex-oriented matching embedding module includes a multi-layer perceptron network with a gate structure and a maximum pooling layer.

[0072] Specifically, a multi-layer perceptron network with a gate structure is used to convert the purified seed graph and target graph into vertex vectors respectively, and a maximum pooling layer is used to aggregate the vertex vectors of the seed graph and target graph into whole graph vectors respectively.

[0073] Specifically, the multilayer perceptron network with a gate structure transforms the vertex vector through the following formula (1):

[0074] h′ i =σ(MLP(h i ))⊙MLP(h i ) (1)

[0075] Among them, h′ i represents the converted output vector, σ represents the sigmoid function, and hi represents the initial vector of the i-th vertex, and MLP represents a multilayer perceptron.

[0076] Specifically, the matching score calculation module is used to identify the dimensions in the whole image vector of the seed image that are greater than a certain threshold T, extract these dimensions in the whole image vectors of the seed image and the target image respectively, and construct two new vectors, namely the seed vector and the target vector, for calculating the matching score.

[0077] 3.2) Using the VME model, the matching score between the seed vector and the target vector is calculated.

[0078] Specifically, the calculated cosine similarity between the two new vectors is used as the matching score:

[0079]

[0080] s′=∪ s[i]>T s[i] (3)

[0081] t′=U s[i]>T t[i] (4)

[0082] Where msc(s, t) represents the matching score between the seed graph and the target graph, ∪ represents connecting the dimensions that meet the conditions, “·” represents calculating the dot product of two vectors, s′ represents the constructed new seed vector, s[i] represents the i-th dimension in the original seed vector, t′ represents the constructed new target vector, and t[i] represents the i-th dimension in the original target vector.

[0083] 3.3) According to the obtained matching scores, all target images to be detected are sorted in descending order, and the K1 target images with the highest ranking are selected as candidate target images.

[0084] 4) Using the optimal vertex matching model, the high-order similarity between the vertices of the candidate target graph and the seed graph is encoded to obtain the similarity between the seed graph and the candidate target graph to obtain the optimal vertex matching result, specifically:

[0085] 4.1) The optimal vertex matching model is used to encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the affinity matrix S.

[0086] Specifically, the optimal vertex matching model adopts the HSE model (High-order Similarity Embedding model), which includes a seed graph convolution module, a target graph convolution module and an affinity measurement function module. The seed graph convolution module is used to encode the structural information of the seed graph into the vertex vector, and obtain a seed graph with vectors as vertices, and each vector contains the semantic information and structural information of the corresponding vertex. The target graph convolution module is used to encode the structural information of the candidate target graph into the vertex vector, and obtain a candidate target graph with vectors as vertices, and each vector contains the semantic information and structural information of the corresponding vertex. The affinity measurement function module is used to input the outputs of the seed graph convolution module and the target graph convolution module into the affinity measurement function to obtain the affinity matrix S.

[0087] Specifically, the seed graph convolution module includes multiple rounds of iterations. In each round of iteration, the vertex vector (vertex feature) is aggregated from the features of its adjacent vertices and the vertex i itself in the previous round. The messages from the adjacent vertices are aggregated using the following formula (5). The message of each adjacent vertex is the feature of the previous round. The conversion f msg , the information of vertex i in the seed graph in the previous round is transformed by the following formula (6): self .f msg and f self All are implemented as neural networks. The following formula (7) is obtained by the aggregation function f aggr Aggregate the two parts of information to update the state of vertex i using represents the eigenvector of vertex i in round k, and is the initial feature vector generated by the BERT model:

[0088]

[0089]

[0090]

[0091] in, represents the message sent by the neighbor to vertex i in the seed graph s in the kth iteration, j represents the neighbor vertex of vertex i, E s represents the set of edges of the seed graph s, It represents the message that vertex i in the seed graph s sends to itself in round k, represents the feature vector of vertex i in the seed graph s at the k-1th round, Represents the feature vector of vertex i in the seed graph s at the kth round.

[0092] Specifically, the target graph convolution module adds an attention mechanism based on the seed graph convolution module. The specific process is as follows:

[0093] ① For vertex p in the candidate target graph t, search for its most similar vertex i in the seed graph:

[0094]

[0095] in, represents the cosine similarity between the feature vectors of vertex p in the candidate target graph t and vertex i in the seed graph s in the kth round.

[0096] ②For each adjacent vertex p′ of vertex p, there is a * The adjacent vertex i *′ Search for the most similar vertex and record the similarity.

[0097] ③ Normalize the similarity and use it as the weight of the message transmitted from the adjacent vertex n to the vertex p (i.e., the attention weight), as shown in the following formula (9):

[0098]

[0099] ④ According to the attention weight, the features of adjacent vertices are fused, as shown in the following formula (10):

[0100]

[0101] in, represents the attention weight of the message propagated from the neighbor vertex n to the vertex p in the candidate target graph t; represents vertex n in the candidate target graph t and vertex i in the seed graph s *′ Cosine similarity between feature vectors in round k; Denotes vertex p′ in the candidate target graph t and vertex i in the seed graph s *′ Cosine similarity between feature vectors in round k; represents the message sent by neighbors to vertex i in the candidate target graph t in the kth iteration, Represents the feature vector of vertex n in the candidate target graph t at the kth round.

[0102] Specifically, in the affinity measurement function, the affinity S between vertex i in the seed graph and vertex p in the candidate target graph is ip for:

[0103]

[0104] Where K represents the number of graph convolutional layers, S∈R+ N×Mrepresents the affinity matrix before normalization, R represents a real number set, N represents the number of vertices in the seed graph, and M represents the number of vertices in the target graph; V s represents the vertex set of the seed graph s, V t represents the vertex set of the candidate target graph t; f aff The specific implementation of the function is:

[0105]

[0106] Among them, W represents the matrix composed of learnable weights of the affinity metric function; τ represents the hyperparameter, and the smaller τ is, the higher the discrimination of the affinity matrix is.

[0107] 4.2) Using the optimal transmission problem solving algorithm (SinkHorn), the obtained affinity matrix S is normalized to obtain the normalized affinity matrix P:

[0108] P=SinkHorn(S) (13)

[0109] 4.3) Using the Hungarian algorithm, the vertex matching results between the seed graph and the candidate target graph are obtained according to the normalized affinity matrix P.

[0110] Specifically, if p max If the following equation is satisfied, then the vertex p in the candidate target graph t max Matches vertex i in the seed graph s.

[0111]

[0112] 4.4) Based on the obtained vertex matching results, calculate the similarity between the seed graph and the candidate target graph.

[0113] Specifically, the similarities of the initial feature vectors between matching vertices are averaged:

[0114]

[0115] Where N is the number of vertices in the seed graph s; p i Denotes the vertices in the candidate target graph t that match the vertex i in the seed graph s. It should be noted that in our model, the candidate target graph with fewer vertices than the seed graph will not be considered.

[0116] 5) According to the similarity between the seed graph and the candidate target graph, determine whether the candidate target graph contains unknown defects similar to the seed defect, specifically:

[0117] 5.1) The similarities between the seed graph and the candidate target graph are averaged and used as the similarity between the candidate target graph and the seed graph.

[0118] 5.2) According to the similarity, the functions corresponding to the candidate target graphs are sorted in descending order to determine whether the candidate target graphs contain unknown defects similar to the seed defects.

[0119] Specifically, all candidate target graphs are sorted in descending order, and the source codes of the functions of the top K2 candidate target graphs corresponding to the candidate target graphs are manually analyzed to confirm whether they contain unknown defects similar to the seed defects.

[0120] Example 2

[0121] like Figure 2 As shown, this embodiment provides a defect detection system for optimal vertex matching, including:

[0122] The seed selection module is used to select a function containing known defects as a seed.

[0123] The data preprocessing module is used to parse the target source code and seeds in the system to be detected into code feature graphs with intermediate statements as vertices in units of functions, and to purify the code feature graphs of the seeds.

[0124] The screening module is used to screen out target code feature graphs that have a high degree of match with the purified seed graph as candidate target graphs.

[0125] The similarity encoding module is used to encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph.

[0126] The defect retrieval module is used to determine whether the candidate target graph contains unknown defects similar to the seed defect based on the similarity between the seed graph and the candidate target graph.

[0127] In a preferred embodiment, it also includes a model training module for training to obtain a VME model and a HSE model.

[0128] In a preferred embodiment, the data preprocessing module includes a parser and a BERT model, wherein the parser is used to parse the function in the source code into a graph with intermediate statement sequences as vertices, and the BERT model is used to embed the intermediate word sequence in each vertex into a vector containing its semantic information.

[0129] The system provided in this embodiment is used to execute the above-mentioned method embodiments. Please refer to the above-mentioned embodiments for specific processes and detailed contents, which will not be repeated here.

[0130] Example 3

[0131] This embodiment provides a processing device corresponding to the optimal vertex matching defect detection system method provided in this embodiment 1. The processing device can be a processing device for a client, such as a mobile phone, a laptop computer, a tablet computer, a desktop computer, etc., to execute the method of embodiment 1.

[0132] The processing device includes a processor, a memory, a communication interface and a bus, and the processor, the memory and the communication interface are connected through the bus to complete mutual communication. The memory stores a computer program that can be run on the processing device, and when the processing device runs the computer program, the optimal vertex matching defect detection system method provided in this embodiment 1 is executed.

[0133] In some implementations, the memory may be a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory.

[0134] In some other implementations, the processor may be a central processing unit (CPU), a digital signal processor (DSP), or other general-purpose processors of various types, which are not limited herein.

[0135] In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0136] Those skilled in the art will understand that the structure of the above-mentioned computing device is only a partial structure related to the scheme of the present application, and does not constitute a limitation on the computing device to which the scheme of the present application is applied. The specific computing device may include more or fewer components, or combine certain components, or have a different arrangement of components.

[0137] Example 4

[0138] This embodiment provides a computer program product corresponding to the optimal vertex matching defect detection system method provided in this embodiment 1. The computer program product may include a computer-readable storage medium on which computer-readable program instructions for executing the optimal vertex matching defect detection system method described in this embodiment 1 are loaded.

[0139] Computer readable storage media can be tangible devices that hold and store instructions used by instruction execution devices. Computer readable storage media can be, for example, but not limited to, electronic storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any combination thereof.

[0140] The above embodiment provides a computer-readable storage medium, whose implementation principle and technical effect are similar to those of the above method embodiment, and will not be repeated here.

[0141] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0142] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0143] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0144] The above embodiments are only used to illustrate the present invention, wherein the structure, connection mode and manufacturing process of each component may be changed. Any equivalent transformations and improvements based on the technical solution of the present invention should not be excluded from the protection scope of the present invention.

Claims

1. A defect detection method based on optimal vertex matching, characterized in that: include: Select a function that contains a known defect as a seed; Taking functions as units, the target source code and seeds in the system to be tested are parsed into code feature graphs with intermediate statements as vertices, and the code feature graphs of the seeds are purified; Filter out the target code feature graphs that have a high matching degree with the purified seed graph as candidate target graphs; Encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph; According to the similarity between the seed graph and the candidate target graph, determining whether the candidate target graph contains an unknown defect similar to the seed defect; The target source code and the seed in the system to be detected are parsed into a code feature graph with the intermediate statement as the vertex, taking the function as the unit, including: Taking functions as units, the target source code and seeds in the system to be tested are parsed respectively to obtain the control flow graph and program dependency graph corresponding to each function; Combining the control flow graph and program dependency graph of each function, a code feature graph with the intermediate statements as vertices is generated; Treat each intermediate sentence as a symbol and the symbol sequence in each function as a sentence, build a corpus, and train the BERT model based on the masked language model; Using the BERT model, each symbol is embedded into a vector. If a vertex in the code feature graph contains only one symbol, the vertex vector is a symbol vector. Otherwise, the symbols in the vertex are connected into a phrase, and the BERT model is used to generate a phrase vector. Each function is converted into a code feature graph with vectors as vertices. Remove the vertices irrelevant to the defect in the seed code feature graph to obtain a purified seed graph; The encoding of the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph includes: The optimal vertex matching model is used to encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the affinity matrix; Normalizing the obtained affinity matrix to obtain a normalized affinity matrix; According to the normalized affinity matrix, the vertex matching results between the seed graph and the candidate target graph are obtained; Based on the obtained vertex matching results, the similarity between the seed graph and the candidate target graph is calculated; The optimal vertex matching model includes: The seed graph convolution module is used to encode the structural information of the seed graph into the vertex vector to obtain a seed graph with vectors as vertices; The target graph convolution module is used to encode the structural information of the candidate target graph into the vertex vector to obtain the candidate target graph with the vector as the vertex; The affinity measurement function module is used to input the outputs of the seed graph convolution module and the target graph convolution module into the affinity measurement function to obtain an affinity matrix.

2. The defect detection method of optimal vertex matching according to claim 1, characterized in that: The method of selecting a target code feature graph having a high matching degree with the seed graph as a candidate target graph and adopting a VME model includes: The purified seed graph and target graph are input into the VME model, and the purified seed graph and target graph are embedded into the seed vector and target vector respectively; Using the VME model, the matching score between the seed vector and the target vector is calculated; According to the obtained matching scores, all target images to be detected are sorted in descending order, and the target images with the highest rankings are selected as candidate target images.

3. The defect detection method of optimal vertex matching according to claim 2, characterized in that: The VME model includes a vertex-oriented matching embedding module and a matching score calculation module, wherein the vertex-oriented matching embedding module includes a multi-layer perceptron network with a gate structure and a maximum pooling layer; A multi-layer perceptron network with a gate structure is used to convert the purified seed graph and target graph into vertex vectors respectively; The maximum pooling layer is used to aggregate the vertex vectors of the seed graph and the target graph into the whole graph vector respectively; The matching score calculation module is used to identify the dimensions in the whole image vector of the seed image that are greater than a certain threshold, extract the dimensions in the whole image vector of the seed image and the target image respectively, and construct the seed vector and the target vector.

4. The defect detection method of optimal vertex matching according to claim 1, characterized in that: The step of determining whether the candidate target graph contains an unknown defect similar to the seed defect according to the similarity between the seed graph and the candidate target graph includes: The similarities between the seed map and the candidate target map are averaged and used as the similarity between the candidate target map and the seed map; According to the similarity, the functions corresponding to the candidate target graphs are sorted in descending order, and the source codes of the functions corresponding to the candidate target graphs with the highest rankings are selected for analysis to confirm whether they contain unknown defects similar to the seed defects.

5. An optimal vertex matching defect detection system, characterized in that: include: The seed selection module is used to select a function containing known defects as a seed; The data preprocessing module is used to parse the target source code and seeds in the system to be detected into code feature graphs with intermediate statements as vertices based on functions, and purify the code feature graphs of the seeds; A screening module is used to screen out target code feature graphs that have a high degree of match with the purified seed graph as candidate target graphs; A similarity encoding module is used to encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph; A defect retrieval module is used to determine whether the candidate target graph contains an unknown defect similar to the seed defect based on the similarity between the seed graph and the candidate target graph; The target source code and the seed in the system to be detected are parsed into a code feature graph with the intermediate statement as the vertex, taking the function as the unit, including: Taking functions as units, the target source code and seeds in the system to be tested are parsed respectively to obtain the control flow graph and program dependency graph corresponding to each function; Combining the control flow graph and program dependency graph of each function, a code feature graph with the intermediate statements as vertices is generated; Treat each intermediate sentence as a symbol and the symbol sequence in each function as a sentence, build a corpus, and train the BERT model based on the masked language model; Using the BERT model, each symbol is embedded into a vector. If a vertex in the code feature graph contains only one symbol, the vertex vector is a symbol vector. Otherwise, the symbols in the vertex are connected into a phrase, and the BERT model is used to generate a phrase vector. Each function is converted into a code feature graph with vectors as vertices. Remove the vertices irrelevant to the defect in the seed code feature graph to obtain a purified seed graph; The encoding of the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the similarity between the seed graph and the candidate target graph includes: The optimal vertex matching model is used to encode the high-order similarities between the vertices of the candidate target graph and the seed graph to obtain the affinity matrix; Normalizing the obtained affinity matrix to obtain a normalized affinity matrix; According to the normalized affinity matrix, the vertex matching results between the seed graph and the candidate target graph are obtained; Based on the obtained vertex matching results, the similarity between the seed graph and the candidate target graph is calculated; The optimal vertex matching model includes: The seed graph convolution module is used to encode the structural information of the seed graph into the vertex vector to obtain a seed graph with vectors as vertices; The target graph convolution module is used to encode the structural information of the candidate target graph into the vertex vector to obtain the candidate target graph with the vector as the vertex; The affinity measurement function module is used to input the outputs of the seed graph convolution module and the target graph convolution module into the affinity measurement function to obtain an affinity matrix.

6. A processing device, characterized in that: The method comprises computer program instructions, wherein the computer program instructions are used to implement the steps corresponding to the optimal vertex matching defect detection system method according to any one of claims 1 to 4 when executed by a processing device.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, wherein the computer program instructions, when executed by a processor, are used to implement the steps corresponding to the optimal vertex matching defect detection system method according to any one of claims 1 to 4.