Data processing method and data system
By converting source code into numeric identifiers and generating code snippets, it solves the problems of large database index and storage occupancy and poor search performance, achieves fast comparison and efficient search, and reduces storage space and processing time.
Patent Information
- Application Number
- CN201910904478.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-09-24
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2039-09-24
AI Technical Summary
When existing technologies use free and open source codes to build databases, they face the problems of large index and storage occupancy and poor search performance. At the same time, the stored duplicate codes may conflict with license conditions, making the task of analyzing the source code complex.
By converting the source code text into a numeric identifier and comparing it with other source code files, a minimum set of consecutive lines is generated as a code fragment, which is compared in the database using a cryptographic hash algorithm to reduce storage usage and improve search efficiency.
It enables fast comparison of software and simplification of database searches, reduces storage space and processing time, avoids access to the original source code, and ensures logical isolation and efficient search.
Smart Images

Figure CN110941726B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to code processing and data technology. The increasing popularity of free and open source code and the increasing concern about license compliance have led to the need to build a database using public free and open source code, with the purpose of identifying the free and open source code contained in a given source code file. Background Art
[0002] In existing technical solutions, since there is a large amount of free and open source code available, indexing and storage becomes a huge challenge due to database footprint and search performance. In addition, the task of analyzing source code is a sensitive issue, and the large amount of duplicate free and open source code stored in the database may conflict with their respective license conditions. Summary of the invention
[0003] The following simplified summary is provided to provide a basic understanding of some aspects of the various invention embodiments described in this disclosure. The summary is not an exhaustive overview of the disclosure. It is neither intended to identify the key / critical elements of the claimed invention nor to describe the scope of the invention. The following summary merely presents some concepts used in the embodiments described in this disclosure in a simplified form as a preface to a more detailed description of those concepts.
[0004] The purpose of some embodiments described in the present disclosure is to provide such a system and method, that is, the system and method convert source code text from any programming language into a series of numeric identifiers for each source code line, and compare these identifiers with other source code files to find matches for subsets of lines. This is achieved by a method of converting source code into symbolic identifiers and comparing them with a data set, in which the source code is used as input code. In this method, simplified source code is generated as output by using at least one of the following method steps: unifying upper and lower case; removing characters; and replacing at least one of characters and keywords with identifiers, and in this method, a minimum set of consecutive line identifiers is generated, the minimum set of consecutive line identifiers is a code snippet, and the following occurrences are found in the data set, which matches a specific range of line identifiers in a specific data set.
[0005] Some embodiments described in the present disclosure are also directed to a data system that converts source code into symbolic identifiers and compares them with a data set, in which the source code is an input code. The data system includes an encoder unit that generates a simplified source code as an output, the encoder unit being configured to perform at least one of the following: unifying the case; removing characters; and replacing at least one of characters and keywords with identifiers, and the data system includes a comparison unit that is configured to: generate a minimum set of consecutive line identifiers, the minimum set of consecutive line identifiers being a code fragment, and find an event in the data set that matches a specific range of line identifiers in a specific data set.
[0006] Embodiments described herein may be based on generating simplified source code as output by using at least one of the following method steps: unifying case; removing characters; and replacing at least one of characters and keywords with identifiers. Embodiments described herein may also be based on comparing identifiers to a data set by generating a minimum set of consecutive row identifiers that produce a match.
[0007] The benefits of the embodiments described herein may be that they may allow software to be compared by comparing their numeric identifiers without the need for the original source code. Furthermore, the data footprint is reduced by only needing to store the numeric identifiers. Furthermore, database searching is simplified by reducing the search to a fixed-length numeric comparison against a data set with an almost perfectly balanced index.
[0008] The foregoing and other objects, features and advantages of the present invention will be more readily understood by considering the following detailed description of the present invention taken in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Exemplary and non-limiting embodiments of the present disclosure and their advantages are described in more detail below with reference to the accompanying drawings, in which:
[0010] Figure 1 A simplified processing of source code text according to an exemplary and non-limiting implementation of the present disclosure is presented.
[0011] Figure 2 Exemplary and non-limiting embodiments of the present disclosure are presented. Figure 1 The generation of line identifiers for simplified code text in .
[0012] Figure 3 Exemplary and non-limiting embodiments of the present disclosure are presented. Figure 2 The code snippet ID of the source code shown.
[0013] Figure 4A system flow diagram is presented according to an exemplary and non-limiting embodiment of the present disclosure. DETAILED DESCRIPTION
[0014] Embodiments described herein allow source code to be compared to data sets without having a copy of the original source code of these data sets. These embodiments also allow row ID generation and database searches to be separated at different locations. Therefore, the individual performing the database search does not need to access the compared code, but only the generated row ID. This logical isolation allows database searches to be completed without accessing the original code or the original source code being compared.
[0015] Additionally, due to the fact that searches are performed against a fixed-length balanced index, the embodiments described herein allow for reduced storage footprint by saving only code snippet IDs (not source code) from large data sets, as well as reduced processing time and faster search responses, a result of the uniform data distribution properties provided by the cryptographic hashing algorithm.
[0016] The term "large data set" is meant to include data sets with more than a billion records, or even up to trillions of results. The embodiments described herein can also be used with smaller data sets, so the size of the data set is not a limiting factor.
[0017] Source code text can be converted into numeric identifiers, thereby allowing rapid comparison between different source code files with tolerance for variations in coding conventions, tabulation, and other grammatical differences in the source code text. The resulting numeric identifiers cannot be converted back to the original source code. The method allows finding source code matches by comparing identifiers without retaining the original source code text.
[0018] Implementations described herein enable fast and efficient comparison of source code with, for example, a large database of previously stored source code line identifiers.Some implementations described herein may perform three steps: reduction, identifier generation, and comparison.
[0019] The generation of the numeric identifier may include two steps: simplification and identification. The simplification step preferably converts the text to a neutral state that allows source code matches to be found regardless of changes in source code indentation, changes in coding conventions, blank lines or spaces, inclusion or exclusion of irrelevant text, or changes in the case of source code instructions.
[0020] The simplification takes the original source code as input and generates a simplified source code as output by applying a series of rules. These rules are divided into: a) make the case uniform, b) replace certain characters or keywords, and c) replace certain characters or keywords (line separators) with chr(10) corresponding to linefeed or new line, d) eliminate empty lines or lines with fewer characters than a predefined threshold.
[0021] The resulting simplified code contains the minimum amount of code per line. For example, assuming a simple configuration of the C programming language, using only brackets and semicolons ({};) as delimiters and not utilizing a 1-byte empty line threshold for any text replacement, such as Figure 1 The conversion source code is shown below.
[0022] Identification is performed by generating fixed-length identifiers on the already simplified source code lines. To ensure uniform distribution of identifier data, a cryptographic hash algorithm is chosen and the resulting hash (or part of the hash) is used as the line identifier.
[0023] For example, assuming that the MD5 hashing algorithm is used and the row ID length is chosen to be 36 bits, Figure 2 The line identifiers for the previous example are presented in . Therefore, the resulting list of line IDs for the original source code is: 28dcdbf4140356bd08e6a0916af6eb265da18ecc79b23c9a6d998a9308eae7ae3855004e.
[0024] In this exemplary case, the 36 bits selected as the row ID identifier provide approximately 68 billion possible IDs, which will certainly lead to a large number of data conflicts. However, the conflicts are resolved by a data comparison method.
[0025] In the comparison step of the source code digital identifier, a minimum set of consecutive lines should be set to generate a match. Such a set of lines is called a code snippet. The minimum number of consecutive code snippets is defined as a threshold for generating a match so that false matches are discarded from the final line ID conflict.
[0026] In the embodiments described herein, false identifications can be avoided. If one calls the amount of bits selected for a fixed length row identifier (W), and calls the minimum number of rows required to match (N), then the smaller is W, and N must be the larger to prevent false positive identifications. Specifically, the smaller W becomes, the greater the likelihood of collisions (i.e., different rows with the same identifier). This can be mitigated by requiring more consecutive rows to match the same file in the database. As the value of N increases, the chance of multiple consecutive rows colliding decreases exponentially.
[0027] The method for comparing source code consists of three steps: generating snippet IDs, searching for the minimum of X consecutive snippet ID occurrences, and selecting the files with the most matches.
[0028] The generation of snippet IDs can be performed by applying the same algorithm used to generate row IDs on a given list of row IDs. For example, given Figure 1 , and considering the code snippet size of 5 lines, the line ID of the first code snippet will be the concatenation of the first 5 line IDs: 28dcdbf4140356bd08e6a0916af6eb265da18ecc79b23. The MD5 hash value of this string is 36d8faf00c3d3d1fd6065737b0c4cf8f, where the first 36 bits of the MD5 hash value are 36d8faf00, which is the first code snippet ID.
[0029] Figure 3 Shows Figure 2 The code snippet IDs of the four sequential code snippets of the source code shown in , each code snippet has five code lines.
[0030] The search operation assumes that the database is loaded with the code snippet IDs of the source code on which the search is to be performed, along with the corresponding metadata from the original source code files. It should be noted that the database need not contain the original source code, but instead only contains the code snippet IDs and metadata from the original code, including but not limited to the file name, original source code location, component / artifact name, etc.
[0031] The searching of the database is preferably performed by finding the code snippet IDs and collecting from the database a list of file IDs that match each code snippet ID. Files with less than a desired number of consecutive code snippet matching events (X) are preferably discarded. The results may preferably be sorted from the highest number to the lowest number of code snippet matching events.
[0032] Figure 4A system and flow chart according to an exemplary and non-limiting embodiment of the present disclosure are shown. The system preferably includes an encoder unit 100 and a comparison unit 102 operatively connected or connectable to a database 104. The encoder unit is configured to receive an input source code at step 106 and convert the input source code into a simplified source code as an output to the comparison unit 102 at step 108. The encoder 100 unit is configured to perform at least one of the following functions: unifying the case, removing characters, and replacing at least one of a character and a keyword with an identifier. The data system can be configured to replace at least one of a character and a keyword with chr(10) as an identifier, which chr(10) corresponds to at least one of a shift code and a line feed code. The identifier can be a numeric identifier. The identifier can be configured to correspond to at least one of a shift code and a line feed code.
[0033] The comparison unit 102 receives the simplified source code and uses the code to generate a minimum set of code snippet IDs (i.e., alphanumeric codes) in the manner described above at step 110, each code snippet ID representing a sequential corresponding set of consecutively numbered encoding line identifiers. At step 112, the comparison unit compares the previously generated code snippets with the code snippets in the encoded data stored in the database 104 to identify any matching codes in the database. The comparison unit 102 preferably outputs and / or stores the data set with the most matches.
[0034] It should be understood by ordinary technicians in this field that it is easy to implement Figure 4 For example, in some embodiments, the encoder unit 100, in addition to generating a simplified code based on the input, can also generate a code fragment of the code and a code fragment ID of the generated code fragment, and forward these code fragment IDs to the comparison unit, which simply performs a comparison of these IDs with those in the database 104.
[0035] Generation of row identifiers may be performed by calculating a numeric identifier for each row of the resulting simplified code. A fixed length identifier is generated by using a cryptographic hash value or a portion of the cryptographic hash value as a fingerprint or identification (ID) for each row of the simplified code.
[0036] In an exemplary embodiment according to the invention, the comparison may be performed by comparing the row identifier with row identifiers stored in a database. A coincidence or match may be found when a minimum number of consecutive row identifiers match.
[0037] In one exemplary embodiment, the data system can be configured to define a threshold amount of characters and eliminate empty lines and lines with fewer characters than the predefined threshold amount of characters. By "threshold amount of characters," it is meant that a minimum number of characters is defined as a threshold, and lines below this threshold are simply ignored. In other words, after code simplification is performed, if the line has less than X characters, then the line is simply ignored. Furthermore, the data system can be configured to search for a defined minimum number of consecutive segment events.
[0038] exist Figure 4 In the system and flow chart, the main operations according to a preferred embodiment of the present disclosure are: receiving source code as input, generating simplified source code, generating a minimum set of consecutive row identifiers, and searching for events in an existing data set that match a specific range of row identifiers in a specific data file.
[0039] The data system can be configured to generate code snippets by applying the same algorithm as that for generating row identifiers on a given row list. The data system (e.g., encoder unit 100 and comparison unit 102) can be implemented, for example, by using the algorithm and implementing processor-based computers and microprocessor technology according to the method of the present invention.
[0040] The specific examples provided in the description given above should not be construed as limiting the scope and / or applicability of the appended claims.
[0041] The terms and expressions which have been employed in the foregoing description are used herein as matters of description and not of limitation, and there is no intention in the use of such terms and expressions to exclude equivalents of the features shown and described or portions thereof, but it is to be appreciated that the scope of the present invention is defined and limited solely by the appended claims.
Claims
1. A data processing method, the data processing method The following steps are involved: Simplifying the input source code to generate a simplified source code by performing at least one of the following: (i) unifying upper and lower case; (ii) remove characters; and (iii) replacing at least one of the character and the keyword with the identifier; Applying a first cryptographic hash to each line in the simplified source code, and for each line, selecting a plurality of bits generated by applying the first cryptographic hash to generate a plurality of line IDs, each line ID representing the content of a line of code in the simplified source code; Applying a second encrypted hash to corresponding groups of the plurality of row IDs, and for each group, selecting a plurality of bits produced by applying the second encrypted hash to generate a plurality of code snippet IDs; searching a data set loaded with code snippet IDs and corresponding metadata of one or more original source code files, wherein a minimum number of consecutive code snippet ID events in the data set is defined as a threshold for generating a match; and selecting the one or more original source code files having the most code snippet ID matches defined by the threshold, Wherein, the first encrypted hash and the second encrypted hash are the same.
2. The data processing method according to claim 1, in, The row ID is a numeric identifier.
3. The data processing method according to claim 1, in, The identifier corresponds to at least one of a line shift code and a line feed code.
4. The data processing method according to claim 1, in, The simplified source code is generated by at least one of: (i) defining a threshold amount of characters; (ii) eliminating blank lines; and (iii) eliminating lines having fewer characters than the defined threshold amount of characters.
5. The data processing method according to claim 4, in, At least one of the character and the keyword is replaced with an identifier corresponding to at least one of the line shift code and the line feed code.
6. A data system, wherein include: An encoder unit that transforms an input code into a simplified source code by performing at least one of the following: (i) unifying case; (ii) remove characters; and (iii) replacing at least one of the character and the keyword with the identifier; a comparison unit, the comparison unit performing the following operations: (i) applying a first encrypted hash to each line in the simplified source code, and for each line, selecting a plurality of bits generated by applying the first encrypted hash to generate a plurality of line IDs, each line ID representing the content of a line of code in the simplified source code; (ii) applying a second encrypted hash to corresponding groups of the plurality of row IDs, and for each group, selecting a plurality of bits produced by applying the second encrypted hash to generate a plurality of code snippet IDs; (iii) searching a data set loaded with code snippet IDs and corresponding metadata of one or more original source code files, wherein a minimum number of consecutive code snippet ID occurrences in the data set is defined as a threshold to produce a match; and (iv) selecting the one or more original source code files having the most code snippet ID matches defined by the threshold, Wherein, the first encrypted hash and the second encrypted hash are the same.
7. The data system according to claim 6, in, The row ID is a numeric identifier.
8. The data system according to claim 6, in, The identifier corresponds to at least one of a line shift code and a line feed code.
9. The data system according to claim 6, in, The simplified source code is generated by at least one of: (i) defining a threshold amount of characters; (ii) eliminating blank lines; and (iii) eliminating lines having fewer characters than the defined threshold amount of characters.
10. The data system according to claim 9, in, At least one of the character and the keyword is replaced with an identifier corresponding to at least one of the line shift code and the line feed code.
Citation Information
Patent Citations
Detection method of code similarity based on digital fingerprints
CN101976318A
Method, device and system for detecting distributed malicious codes on basis of textures
CN104751055A
Source code function sample extraction method and device, computing equipment and storage medium
CN107678968A
Code data feature extraction and retrieval method and device
CN115238102A
Retrieval processing method, data generation method, and information processor
JP2014098989A
