Code detection method, device and equipment
By slicing and comparing code snippets in differential format files, and updating and inputting them into the large model, the problems of high false positive rates and low positive recall rates in code detection are solved, and more efficient and accurate code detection is achieved.
Patent Information
- Application Number
- CN202411843929.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-03-25
AI Technical Summary
The existing technology has a high false alarm rate during code detection, resulting in a low forward recall rate and is difficult to effectively improve.
By obtaining the unified differential format file, slice it into a differential slice, and comparing it with the candidate code snippets generated by the Abstract Syntax Tree (AST), the specified code snippet is determined to update the differential format file, and input it into a pre-trained large model for detection.
It improves the forward recall rate of code detection, reduces the false positive rate, and at the same time enhances the static search capability, improving detection efficiency and accuracy.
Smart Images

Figure CN119690803A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and more specifically, to a method, device and equipment for code detection. Background Art
[0002] In the process of software development, it is often necessary to modify the source code, test the modified code, and then display the test results to the user, and the user modifies the modified code again according to the test results.
[0003] In the prior art, a unified difference format (Unified Diff) text is first determined based on the source code and the modified code, and then a detection result is generated based on the Unified Diff text. Specifically, an open source diff processing method is used. However, the above method may lead to a high false alarm rate. In order to reduce the false alarm rate, the Unified Diff text is sliced and an interceptor is added. Although the false alarm rate is reduced, the positive recall rate is also reduced.
[0004] To sum up, how to improve the positive recall rate during code detection is a problem that needs to be solved at present. Summary of the invention
[0005] In view of this, embodiments of the present invention provide a method, apparatus and device for code detection, which can improve the positive recall rate during code detection.
[0006] In a first aspect, an embodiment of the present invention provides a method for code detection, the method comprising:
[0007] Obtain a unified difference format file, wherein the unified difference format file represents the difference between a first file and a second file, and the first file and the second file respectively include a plurality of codes;
[0008] Slicing the unified difference format file to generate at least one difference slice;
[0009] Compare each of the difference slices with a plurality of candidate code snippets in the second file, wherein the second file generates a plurality of candidate code snippets through an abstract syntax tree AST;
[0010] In response to a successful comparison between the difference slice and any one of the multiple candidate code segments, determining the successfully compared candidate code segment as a designated code segment;
[0011] Updating the unified difference format file according to the specified code snippet;
[0012] The updated unified difference format file is input into the pre-trained large model, and the detection result is output.
[0013] Optionally, the method further includes:
[0014] In response to the difference slice failing to be compared with all of the plurality of candidate code snippets, obtaining context information of a set number of lines originally contained in the difference slice in the unified difference format file;
[0015] The context information is determined to be a specified code fragment.
[0016] Optionally, the method further includes:
[0017] A first file is obtained, wherein the first file is an original code file.
[0018] Optionally, the method further includes:
[0019] Obtain a second file, wherein the second file is a code file generated after the first file is modified;
[0020] The second file is sliced by using the AST to generate the multiple candidate code snippets.
[0021] Optionally, the method further includes:
[0022] The unified difference format file is generated according to the first file and the second file.
[0023] Optionally, the modification includes updating and adding.
[0024] Optionally, updating the unified difference format file according to the specified code snippet specifically includes:
[0025] Determine context information of a set number of lines originally included in the difference slice in the unified difference format file;
[0026] The specified code snippet replaces the difference slice and its context information to generate an updated unified difference format file.
[0027] In a second aspect, an embodiment of the present invention provides a device for code detection, the device comprising:
[0028] An acquiring unit, configured to acquire a unified difference format file, wherein the unified difference format file indicates a difference between a first file and a second file, and the first file and the second file respectively include a plurality of codes;
[0029] A processing unit, configured to slice the unified difference format file to generate at least one difference slice;
[0030] A comparison unit, configured to compare each of the difference slices with a plurality of candidate code snippets in the second file, wherein the second file generates the plurality of candidate code snippets through an abstract syntax tree AST;
[0031] a determining unit, in response to a successful comparison between the difference slice and any one of the plurality of candidate code segments, configured to determine the successfully compared candidate code segment as a designated code segment;
[0032] An updating unit, configured to update the unified difference format file according to the specified code snippet;
[0033] The output unit is used to input the updated unified difference format file into the pre-trained large model and output the detection result.
[0034] Optionally, the determining unit is further configured to:
[0035] In response to the difference slice failing to be compared with all of the plurality of candidate code snippets, obtaining context information of a set number of lines originally contained in the difference slice in the unified difference format file;
[0036] The context information is determined to be a specified code fragment.
[0037] Optionally, the acquisition unit is further used for:
[0038] A first file is obtained, wherein the first file is an original code file.
[0039] Optionally, the acquisition unit is further used for:
[0040] Obtain a second file, wherein the second file is a code file generated after the first file is modified;
[0041] The processing unit is further configured to slice the second file through the AST to generate the plurality of candidate code snippets.
[0042] Optionally, the processing unit is further used for:
[0043] The unified difference format file is generated according to the first file and the second file.
[0044] Optionally, the modification includes updating and adding.
[0045] Optionally, the updating unit is specifically used for:
[0046] Determine context information of a set number of lines originally included in the difference slice in the unified difference format file;
[0047] The specified code snippet replaces the difference slice and its context information to generate an updated unified difference format file.
[0048] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, the memory being used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement a method as described in the first aspect or any possible embodiment of the first aspect.
[0049] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement a method as described in the first aspect or any possible embodiment of the first aspect.
[0050] In an embodiment of the present invention, a unified difference format file is obtained, wherein the unified difference format file represents the difference between a first file and a second file, and the first file and the second file respectively include multiple codes; the unified difference format file is sliced to generate at least one difference slice; each of the difference slices is compared with multiple candidate code fragments in the second file, wherein the second file generates multiple candidate code fragments through an abstract syntax tree AST; in response to the successful comparison between the difference slice and any one of the multiple candidate code fragments, the candidate code fragment that successfully compares is determined as a designated code fragment; the unified difference format file is updated according to the designated code fragment; the updated unified difference format file is input into a pre-trained large model, and a detection result is output. Through the above method, AST is used to implement static retrieval enhancement, a designated code fragment associated with the difference slice is obtained, and the difference slice and its corresponding designated code fragment are input into the large model together, which can improve the positive recall rate of code detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:
[0052] Figure 1 is a flow chart of a code detection method in an embodiment of the present invention;
[0053] Figure 2 is a flow chart of another method for code detection in an embodiment of the present invention;
[0054] Figure 3 is a flow chart of another method for code detection in an embodiment of the present invention;
[0055] Figure 4is a schematic diagram of a code detection device in an embodiment of the present invention;
[0056] Figure 5 is a schematic diagram of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0057] The present application is described below based on embodiments, but the present application is not limited to these embodiments. In the detailed description of the present application below, some specific details are described in detail. It is possible for those skilled in the art to fully understand the present application without the description of these details. In order to avoid confusing the essence of the present application, known methods, processes, flows, components and circuits are not described in detail.
[0058] In addition, persons of ordinary skill in the art will appreciate that the drawings provided herein are for illustration purposes and are not necessarily drawn to scale.
[0059] Unless the context clearly requires otherwise, the words "include", "comprising" and similar words throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, the meaning is "including but not limited to".
[0060] In the description of this application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of this application, unless otherwise specified, the meaning of "plurality" is two or more.
[0061] In the prior art, when detecting the Unified Diff text, an open source diff processing method is used. Generally, two methods are used, as follows: Method 1: input the original format of the Unified Diff text into the large model. Since the large model uses the Unified Diff text during training, the Unified Diff text will not be specially processed, and it is only arranged and combined according to the language characteristics of the Unified Diff text. The disadvantage is that the original format of the Unified Diff text is difficult to understand, which makes it easy for the large model to be unable to distinguish between the code before and after the modification. The code comprehension ability of the large model is very high, so the positive recall rate of code detection is relatively high; Method 2: split the Unified Diff text into two ordinary format codes, old hunk and new hunk, and input the split old hunk and new hunk into the large model at the same time, so that the large model can understand the code. However, since the simultaneous input of old hunk and new hunk will make the context input to the large model too long, it not only consumes a lot of resources but also has poor concentration, affecting the judgment of the large model and making it more likely to be false positives. Therefore, how to improve the positive recall rate during code detection is a problem that needs to be solved at present.
[0062] In the embodiment of the present invention, the large model may also be referred to as an artificial intelligence (AI) model or a large language model (LLM), wherein the large language model is a deep learning model based on a transformer architecture, which can process and generate natural language text, is usually trained on a large amount of text data, has the ability to understand and generate language, and is widely used in dialogue systems, text generation and other natural language processing tasks. In the embodiment of the present invention, the large model is used for code detection, which may also be referred to as code review, and is used to detect problems that arise after code modification and feed back the problems to users for correction.
[0063] In the embodiment of the present invention, the positive recall rate indicates that the detected problem is a real problem rather than a false positive problem, wherein the false positive refers to that the large model responds to a code error when detecting the Unified Diff text, but in fact there is no error in the code; and, the embodiment of the present invention not only needs to improve the positive recall rate but also needs to reduce the false negative problem, wherein the false negative refers to that the large model does not respond to a code error when detecting the Unified Diff text, but in fact there is still an error in the code.
[0064] In order to solve the above problems, a method for code detection is proposed in the embodiment of the present invention. Figure 1As shown, the method includes:
[0065] Step S101: Obtain a unified difference format file.
[0066] Specifically, the unified difference format (Unified Diff) file represents the difference between a first file and a second file, and the first file and the second file respectively include a plurality of codes.
[0067] In a possible implementation, the Unified Diff is a variant of the context format, omitting redundant context lines and making the format more compact. When generating the Unified Diff, the parameter lines is set to indicate the number of context lines to be displayed for the modified code, which is generally set to three lines by default. Specifically, GNUdiff can be used to generate the Unified Diff format, wherein the GNU diff is a command line tool widely used in UNIX and UNIX-like systems for comparing the difference contexts of two files or directories.
[0068] In a possible implementation, the user modifies the first file to generate the second file, and then generates the Unified Diff file according to GNU diff. In addition to displaying the modified code, the Unified Diff file also displays N lines of code above and below the modified code, where N is a positive integer greater than or equal to 0. Assume that N is 3. The example is as follows:
[0069]
[0070]
[0071] The above-mentioned Unified Diff file has a specific format, specifically, the "---" represents the file name before the change, and the "+++" represents the file name after the change; a line starting and ending with "@@" indicates the range of lines that have changed, for example, "@@-1,7+1,7@@" means that there are differences between the 7 consecutive lines starting from the 1st line of the first file and the 7 consecutive lines starting from the 1st line of the second file; each line is preceded by an identifier to indicate that the line is deleted in the original file (indicated by "-"), added in the modified file (indicated by "+") or not modified (indicated by a space). The above-mentioned Unified Diff file is only an exemplary description, and the specific shortcomings will depend on the actual situation.
[0072] Step S102: Slice the unified difference format file to generate at least one difference slice.
[0073] Specifically, each line of modified code is sliced, and each slice is called a difference slice.
[0074] Step S103: compare each of the difference slices with a plurality of candidate code snippets in the second file.
[0075] Specifically, the second file generates a plurality of candidate code snippets through an Abstract Syntax Tree (AST).
[0076] In a possible implementation, the abstract syntax tree may also be called a syntax tree, which is an abstract representation of the syntax structure of the source code, and represents the syntax structure of the programming language in a tree form. Each node on the syntax tree represents a structure in the source code, and the syntax does not represent every detail that appears in the real syntax. For example, nested parentheses are implied in the tree structure and are not presented in the form of nodes; and conditional jump statements such as if-condition-then can be represented using nodes with three branches.
[0077] In an embodiment of the present invention, the code in the second file can be segmented by the AST so that the candidate code fragments generated by the segmentation have grammatical integrity, wherein each candidate code fragment corresponds to a node type of an abstract syntax tree in a Java programming language, for example, FieldDeclaration, MethodDeclaration, ConstructorDeclaration, InitializerDeclaration, InnerClassOrInterfaceDeclaration, InnerEnumDeclaration, AnnotationMemberDeclaration, EnumConstantDeclaration, RecordDeclaration, and CompactConstructorDeclaration.
[0078] Specifically, the FieldDeclaration represents a field declaration in a class and defines variables in the class.
[0079] For example:
[0080]
[0081] The MethodDeclaration represents a method declaration in a class, defining a function that can be called on instances of the class.
[0082] For example:
[0083]
[0084] The ConstructorDeclaration represents a constructor declaration in a class, defining a special method for initializing class objects.
[0085] For example:
[0086]
[0087] The InitializerDeclaration represents a static initializer block declaration in a class, defining a code block that is executed when the class is loaded.
[0088] For example:
[0089]
[0090] The InnerClassOrInterfaceDeclaration represents an inner class or interface declaration in a class, defining a nested class or interface in an outer class.
[0091] For example:
[0092]
[0093] The InnerEnumDeclaration represents an inner enumeration type declaration in a class, defining a nested enumeration type in an outer class.
[0094] For example:
[0095]
[0096] The AnnotationMemberDeclaration represents a member declaration in an annotation type, defining members that can be used in an annotation.
[0097] For example:
[0098]
[0099]
[0100] The EnumConstantDeclaration represents a constant declaration in an enumeration type, defining named constants in the enumeration type.
[0101] For example:
[0102]
[0103] The RecordDeclaration represents the internal record in the class. It is a new feature of JDK14 and is a new type of type declaration. Record is a restricted form of the class.
[0104] For example:
[0105]
[0106] The CompactConstructorDeclaration represents the constructor of the record class and defines a special method for initializing class objects. Compared with the standard constructor, it does not allow parameters.
[0107] For example:
[0108]
[0109] This is only an example description, and the specific segmentation of the candidate code snippets is determined according to the actual situation.
[0110] In one possible implementation, the import, stream, and other codes are not split.
[0111] Step S104: in response to a successful comparison between the difference slice and any one of the multiple candidate code segments, determining the successfully compared candidate code segment as a designated code segment.
[0112] Specifically, the comparison is successful when the candidate code segment contains the content of the difference slice, and the designated code segment corresponding to the difference slice is determined.
[0113] Step S105: updating the unified difference format file according to the specified code snippet.
[0114] Specifically, the context information of the original set number of lines of the difference slice in the unified difference format file is determined; the difference slice and its context information are replaced by the specified code fragment to generate an updated unified difference format file.
[0115] In a possible implementation, an example of the updated unified difference format file is as follows:
[0116]
[0117]
[0118] In the above-mentioned updated unified difference format file, taking the second modified code as an example, the second modification is to add the code "AtomicBoolean isFinished = new AtomicBoolean(false)", to determine that the specified code snippet exists, and therefore updating the specified code snippet to the unified difference format file will increase the original context content, but the added content is a fragment with a grammatical structure generated by AST, which realizes static retrieval enhancement without adding irrelevant code.
[0119] Step S106: input the updated unified difference format file into the pre-trained large model and output the detection result.
[0120] Specifically, after the updated unified difference format file is input into the pre-trained large model, the large model will output the retrieval result after thinking.
[0121] In a possible implementation, the step S103 may further include other steps, such as Figure 2 Said, including:
[0122] Step S107: in response to the difference slice failing to be compared with all the multiple candidate code snippets, obtaining the context information of a set number of lines originally in the unified difference format file for the difference slice, and determining the context information as a designated code snippet.
[0123] Specifically, as in the example of the updated unified difference format file above, the first modified code import does not have a corresponding specified code snippet, so the original context is maintained.
[0124] In a possible implementation, the step S101 may further include other steps, such as Figure 3 Said, including:
[0125] Step S108: Obtain the first file.
[0126] The first file is an original code file.
[0127] Step S109: Obtain the second file.
[0128] The second file is a code file generated after the first file is modified;
[0129] Step S110: Slice the second file through the AST to generate the multiple candidate code snippets.
[0130] Step S111: Generate the unified difference format file according to the first file and the second file.
[0131] In a possible implementation manner, the modification includes updating and adding.
[0132] Specifically, since the intention to delete files during code detection is difficult to reflect at the code level, it generally requires the support of context such as project background and requirement background. Files will not be associated during code detection, so deleted files cannot play a role in supplementing the context. Therefore, the embodiment of the present invention only detects new code and changed code, which will not cause duplication and expansion of the context, thereby improving the efficiency and accuracy of code detection.
[0133] Through the above embodiment, AST static retrieval enhancement technology is introduced in the process of code detection, and a specified code snippet with grammatical integrity with the modified code is obtained, and the specified code snippet is combined with Unified Diff and input into the large model. Since the combination of the specified code snippet and Unified Diff reasonably increases the input content, it will also improve the performance of the large model, thereby improving the efficiency and accuracy of code detection.
[0134] In an embodiment of the present invention, a device for code detection is provided, such as Figure 4 As shown, it specifically includes: an acquisition unit 401, a processing unit 402, a comparison unit 403, a determination unit 404, an update unit 405 and an output unit 406, wherein the acquisition unit 401 is used to acquire a unified difference format file, wherein the unified difference format file represents the difference between a first file and a second file, and the first file and the second file respectively include multiple codes; the processing unit 402 is used to slice the unified difference format file to generate at least one difference slice; the comparison unit 403 is used to compare each of the difference slices with multiple candidate code fragments in the second file, wherein the second file generates multiple candidate code fragments through an abstract syntax tree AST; the determination unit 404, in response to the difference slice being successfully compared with any one of the multiple candidate code fragments, is used to determine the candidate code fragment that has been successfully compared as a specified code fragment; the update unit 405 is used to update the unified difference format file according to the specified code fragment; the output unit 406 is used to input the updated unified difference format file into a pre-trained large model and output the detection result.
[0135] Furthermore, the determining unit is further configured to:
[0136] In response to the difference slice failing to be compared with all of the plurality of candidate code snippets, obtaining context information of a set number of lines originally contained in the difference slice in the unified difference format file;
[0137] The context information is determined to be a specified code fragment.
[0138] Furthermore, the acquisition unit is also used for:
[0139] A first file is obtained, wherein the first file is an original code file.
[0140] Furthermore, the acquisition unit is also used for:
[0141] Obtain a second file, wherein the second file is a code file generated after the first file is modified;
[0142] The processing unit is further configured to slice the second file through the AST to generate the plurality of candidate code snippets.
[0143] Furthermore, the processing unit is also used for:
[0144] The unified difference format file is generated according to the first file and the second file.
[0145] Furthermore, the modification includes updating and adding.
[0146] Furthermore, the updating unit is specifically used for:
[0147] Determine context information of a set number of lines originally included in the difference slice in the unified difference format file;
[0148] The specified code snippet replaces the difference slice and its context information to generate an updated unified difference format file.
[0149] Figure 5 Schematic diagram of the structure of the electronic device in the embodiment of the present invention. Figure 5As shown, it includes a general computer hardware structure, which at least includes a processor 501 and a memory 502. The processor 501 and the memory 502 are connected via a bus 503. The memory 502 is suitable for storing instructions or programs executable by the processor 501. The processor 501 can be an independent microprocessor or a collection of one or more microprocessors. Thus, the processor 501 executes the instructions stored in the memory 502, thereby executing the method flow of the embodiment of the present invention as described above to realize the processing of data and the control of other devices. The bus 503 connects the above-mentioned multiple components together, and at the same time connects the above-mentioned components to the display controller 504 and the display device and the input / output (I / O) device 505. The input / output (I / O) device 505 can be a mouse, a keyboard, a modem, a network interface, a touch input device, a somatosensory input device, a printer, and other devices known in the art. Typically, the input / output device 505 is connected to the system through an input / output (I / O) controller 506.
[0150] Among them, the instructions stored in the memory 502 are executed by at least one processor 501 to implement: obtaining a unified difference format file, wherein the unified difference format file represents the difference between a first file and a second file, and the first file and the second file respectively include multiple codes; slicing the unified difference format file to generate at least one difference slice; comparing each of the difference slices with multiple candidate code fragments in the second file, wherein the second file generates multiple candidate code fragments through an abstract syntax tree AST; in response to the difference slice being successfully compared with any one of the multiple candidate code fragments, determining the successfully compared candidate code fragment as a designated code fragment; updating the unified difference format file according to the designated code fragment; inputting the updated unified difference format file into a pre-trained large model to output a detection result.
[0151] Specifically, the electronic device includes: one or more processors 501 and a memory 502, Figure 5 Take a processor 501 as an example. The processor 501 and the memory 502 may be connected via a bus or other means. Figure 5 In the example, the bus connection is used. The memory 502 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The processor 501 executes various functional applications and data processing of the device by running the non-volatile software programs, instructions and modules stored in the memory 502, that is, the above-mentioned method for determining code detection is implemented.
[0152] The memory 502 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store a list of options, etc. In addition, the memory 502 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 502 may optionally include a memory remotely arranged relative to the processor 501, and these remote memories may be connected to an external device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0153] One or more modules are stored in the memory 502, and when executed by one or more processors 501, the code detection method in any of the above method embodiments is executed.
[0154] As will be appreciated by those skilled in the art, various aspects of the embodiments of the present invention may be implemented as a system, method or computer program product. Therefore, various aspects of the embodiments of the present invention may take the form of a complete hardware implementation, a complete software implementation (including firmware, resident software, microcode, etc.), or an implementation that combines software aspects with hardware aspects, which may generally be referred to herein as a "circuit," "module," or "system." In addition, various aspects of the embodiments of the present invention may take the form of a computer program product implemented in one or more computer-readable media having a computer-readable program code implemented thereon.
[0155] Any combination of one or more computer-readable media can be utilized. Computer-readable media can be computer-readable signal media or computer-readable storage media. Computer-readable storage media can be, for example, (but not limited to) electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or apparatuses, or any suitable combination of the foregoing. More specific examples (non-exhaustive enumeration) of computer-readable storage media will include the following: an electrical connection with one or more wires, a portable computer floppy disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of an embodiment of the present invention, a computer-readable storage medium can be any tangible medium that can contain or store a program used by an instruction execution system, device or apparatus or a program used in conjunction with an instruction execution system, device or apparatus.
[0156] A computer readable signal medium may include a propagated digital signal having a computer readable program code implemented therein, such as in baseband or as part of a carrier wave. Such propagated signals may take any of a variety of forms, including but not limited to electromagnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any of the following computer readable media: not a computer readable storage medium, and may communicate, propagate, or transmit a program used by or in conjunction with an instruction execution system, device, or apparatus.
[0157] Program code embodied on a computer readable medium may be transmitted using any appropriate medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0158] The computer program code for performing operations for various aspects of the embodiments of the present invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, Smalltalk, C++, etc., and conventional process programming languages such as "C" programming language or similar programming languages. The program code can be executed completely on the user's computer, partially on the user's computer as a stand-alone software package; partially on the user's computer and partially on a remote computer; or completely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer through any type of network including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., by using the Internet of an Internet service provider).
[0159] The flowchart legend and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present invention described above describe various aspects of the embodiment of the present invention.It will be understood that each block of the flowchart legend and / or block diagram and the combination of the blocks in the flowchart legend and / or block diagram can be implemented by computer program instructions.These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer or other programmable data processing device to produce a machine so that the instructions (executed by the processor of the computer or other programmable data processing device) create a device for implementing the function / action specified in the flowchart and / or block diagram block or block.
[0160] These computer program instructions may also be stored in a computer-readable medium that can direct a computer, other programmable data processing device, or other apparatus to operate in a particular manner, so that the instructions stored in the computer-readable medium produce an article of manufacture including instructions for implementing the functions / actions specified in the flowchart and / or block diagram blocks or blocks.
[0161] The computer program instructions may also be loaded onto a computer, other programmable data processing device or other apparatus so that a series of operable steps are performed on the computer, other programmable device or other apparatus to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide a process for implementing the functions / actions specified in the flowchart and / or block diagram block or blocks.
[0162] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0163] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portals for users to choose to authorize or refuse. Users' refusal to process personal information other than the necessary information required for basic functions will not affect the user's use of basic functions.
Claims
1. A code detection method, characterized in that: The method comprises: Obtain a unified difference format file, wherein the unified difference format file represents the difference between a first file and a second file, and the first file and the second file respectively include a plurality of codes; Slicing the unified difference format file to generate at least one difference slice; Compare each of the difference slices with a plurality of candidate code snippets in the second file, wherein the second file generates a plurality of candidate code snippets through an abstract syntax tree AST; In response to a successful comparison between the difference slice and any one of the multiple candidate code segments, determining the successfully compared candidate code segment as a designated code segment; Updating the unified difference format file according to the specified code snippet; The updated unified difference format file is input into the pre-trained large model, and the detection result is output.
2. The method according to claim 1, characterized in that The method further comprises: In response to the difference slice failing to be compared with all of the plurality of candidate code snippets, obtaining context information of a set number of lines originally contained in the difference slice in the unified difference format file; The context information is determined to be a specified code fragment.
3. The method according to claim 1, characterized in that The method further comprises: A first file is obtained, wherein the first file is an original code file.
4. The method according to claim 3, characterized in that The method further comprises: Obtain a second file, wherein the second file is a code file generated after the first file is modified; The second file is sliced by using the AST to generate the multiple candidate code snippets.
5. The method according to claim 4, characterized in that The method further comprises: The unified difference format file is generated according to the first file and the second file.
6. The method according to claim 4, characterized in that Said modifications include updates and additions.
7. The method according to claim 1, characterized in that The updating of the unified difference format file according to the specified code snippet specifically includes: Determine context information of a set number of lines originally included in the difference slice in the unified difference format file; The specified code snippet replaces the difference slice and its context information to generate an updated unified difference format file.
8. A code detection device, characterized in that: The device comprises: An acquiring unit, configured to acquire a unified difference format file, wherein the unified difference format file indicates a difference between a first file and a second file, and the first file and the second file respectively include a plurality of codes; A processing unit, configured to slice the unified difference format file to generate at least one difference slice; A comparison unit, configured to compare each of the difference slices with a plurality of candidate code snippets in the second file, wherein the second file generates the plurality of candidate code snippets through an abstract syntax tree AST; a determining unit, in response to a successful comparison between the difference slice and any one of the plurality of candidate code segments, configured to determine the successfully compared candidate code segment as a designated code segment; An updating unit, configured to update the unified difference format file according to the specified code snippet; The output unit is used to input the updated unified difference format file into the pre-trained large model and output the detection result.
9. An electronic device, comprising a memory and a processor, characterized in that: The memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.