Index cross-border test method, computer equipment and computer program product

By constructing the correlation relationship between the target feature structure and the out-of-bounds protection structure, the problem of narrow application scope of index out-of-bounds testing in the existing technology is solved, and effective testing of more data types and code structures is achieved.

CN119902979AActive Publication Date: 2025-04-29TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411905807.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-04-29
Estimated Expiration
2044-12-23

AI Technical Summary

Technical Problem

The existing index out-of-bounds testing methods have a narrow scope of application and cannot be effectively applied to data types such as OC languages ​​and variable arrays for dynamic calculations.

Method used

By obtaining the index of the target feature structure and the out-of-bounds protection structure in the code to be tested, the association relationship between the target feature structure and the out-of-bounds protection structure is constructed, and the index out-of-bounds test results are obtained.

Benefits of technology

It improves the scope of application of index out-of-bounds testing methods, making them suitable for more data types and code structures, and enhances the comprehensiveness and accuracy of testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902979A_ABST
    Figure CN119902979A_ABST
Patent Text Reader

Abstract

The invention relates to an index cross-border test method, computer equipment and a computer program product. The method comprises the steps of obtaining a to-be-tested code, and obtaining at least one target feature structure contained in the to-be-tested code and a first index corresponding to each target feature structure; the target feature structure is a feature structure with an index border crossing risk; obtaining at least one border-crossing protection structure contained in the to-be-tested code, and obtaining a second index corresponding to each border-crossing protection structure; based on each first index and each second index, obtaining an association relationship between each target feature structure and each border-crossing protection structure; and according to the association relationship, obtaining an index border crossing test result of each target feature structure in the to-be-tested code. By adopting the method, an array border crossing test can be prevented from being realized by adopting a memory offset or based on a function call relationship, so that the application range of the index border crossing test method can be expanded.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an index out-of-bounds testing method, a computer device, and a computer program product. Background Art

[0002] An index out of bounds error means that when accessing an array, string, or other collection data structure, an index that exceeds its actual range is used. This error will cause the program to crash. For example, when accessing an array or string, if the index is less than 0 or greater than or equal to the length of the array or string, an index out of bounds error will occur, causing the program to crash. Therefore, in order to avoid program crashes, it is usually necessary to perform an index out of bounds test on the application to ensure stable operation of the application.

[0003] In traditional technology, index out-of-bounds testing can usually be performed in the following two ways: array out-of-bounds testing based on memory offsets, and array access range out-of-bounds testing based on function call relationships. However, array out-of-bounds testing based on memory offsets requires calculations at compile time, which is not suitable for OC languages ​​with dynamic calculations. The test scheme for array access range calculations based on function call relationships is limited to immutable arrays, and the coverage is not comprehensive enough. In addition, code out-of-bounds behavior in OC languages ​​usually does not involve function call relationships. The length of variable arrays in OC cannot be calculated in static code, so it is also not applicable. It can be seen that the existing index out-of-bounds testing can only be applied to code of specific data types, so the scope of application of the existing index out-of-bounds testing methods is relatively narrow. Summary of the invention

[0004] Based on this, it is necessary to provide an index out-of-bounds testing method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the scope of application of the index out-of-bounds testing method in response to the above technical problems.

[0005] In a first aspect, the present application provides an index out-of-bounds testing method, comprising:

[0006] Acquire the code to be tested, and acquire at least one target feature structure contained in the code to be tested, and a first index corresponding to each target feature structure; the target feature structure is a feature structure with a risk of index crossing the boundary;

[0007] Obtain at least one out-of-bounds protection structure included in the code to be tested, and obtain a second index corresponding to each of the out-of-bounds protection structures;

[0008] Based on each of the first indexes and each of the second indexes, acquiring an association relationship between each of the target feature structures and each of the cross-boundary protection structures;

[0009] According to the association relationship, an index out-of-bounds test result of each target feature structure in the code to be tested is obtained.

[0010] In one of the embodiments, based on each of the first indexes and each of the second indexes, obtaining the association relationship between each of the target feature structures and each of the cross-boundary protection structures includes: obtaining a current first index, and a current target feature structure corresponding to the current first index; the current first index is any one of the first indexes; when there is a current second index matching the current first index in each of the second indexes, obtaining a current cross-boundary protection structure corresponding to the current second index; and constructing an association relationship between the current target feature structure and the current cross-boundary protection structure.

[0011] In one embodiment, after obtaining the current first index and the current target feature structure corresponding to the current first index, it also includes: when any of the second indexes satisfies a preset matching condition, using the second index as the current second index that matches the current first index; the preset matching condition includes: the out-of-bounds protection structure corresponding to the second index and the current target feature structure are located in the same function method; the index identifier corresponding to the second index is the same as the index identifier corresponding to the current first index; the code line number where the second index is located is located before the code line number where the current first index is located.

[0012] In one of the embodiments, the index out-of-bounds test result of each target feature structure in the code to be tested is obtained based on the association relationship, including: when the association relationship includes the association relationship between the current target feature structure and the current out-of-bounds protection structure, obtaining the index attribute of the current first index and the structural attribute of the current out-of-bounds protection structure; when the structural attribute matches the index attribute, determining that the index out-of-bounds test result of the current target feature structure is a passed test; when the structural attribute does not match the index attribute, determining that the index out-of-bounds test result of the current target feature structure is a failed test.

[0013] In one embodiment, the index attribute includes a first index attribute and a second index attribute, and the structure attribute includes a first structure attribute, a second structure attribute and a third structure attribute; the first index attribute indicates that the first index has a property restriction condition that is always greater than 0, and the second index attribute indicates that the first index does not have the property restriction condition; the first structure attribute indicates that the cross-border protection structure is used to determine whether the first index is greater than 0, the second structure attribute indicates that the cross-border protection structure is used to determine whether the first index is less than the length of the indexed object, and the third structure attribute indicates that the cross-border protection structure is used to determine whether the first index is greater than 0 and whether the first index is less than the length of the indexed object; after obtaining the index attribute of the current first index and the structure attribute of the current cross-border protection structure, it also includes: when the index attribute is the first index attribute, if the structure attribute of the current cross-border protection structure is the second structure attribute or the third structure attribute, determining that the structure attribute matches the index attribute; when the index attribute is the second index attribute, if the structure attribute of the current cross-border protection structure is the third structure attribute, or the structure attribute of the current cross-border protection structure includes both the first structure attribute and the second structure attribute, determining that the structure attribute matches the index attribute.

[0014] In one of the embodiments, after obtaining the current first index and the current target feature structure corresponding to the current first index, it also includes: when there is no current second index matching the current first index in each of the second indexes, determining that there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested; obtaining the index out-of-bounds test result of each of the target feature structures in the code to be tested based on the association relationship, including: when there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested, determining that the index out-of-bounds test result of the current target feature structure is a test failure.

[0015] In one of the embodiments, obtaining at least one target feature structure contained in the code to be tested includes: obtaining a preset target feature structure rule table; the target feature structure rule table stores target method names corresponding to each target feature structure, and target object types of calling objects that call each feature structure; obtaining method names of each feature structure contained in the code to be tested, and object types of calling objects that call each feature structure; when the method name of any feature structure matches the target method name stored in the target feature structure rule table, and the object type matches the target object type corresponding to the target method name, determining that the feature structure is the target feature structure.

[0016] In one of the embodiments, obtaining at least one out-of-bounds protection structure contained in the code to be tested includes: obtaining a preset out-of-bounds protection structure rule table; the out-of-bounds protection structure rule table stores code writing rules for each out-of-bounds protection structure; if any sub-code structure in the code to be tested satisfies any code writing rule stored in the out-of-bounds protection structure rule table, determining that the sub-code structure is an out-of-bounds protection structure contained in the code to be tested.

[0017] In a second aspect, the present application further provides an index out-of-bounds testing device, comprising:

[0018] A first index acquisition module is used to acquire the code to be tested, and acquire at least one target feature structure contained in the code to be tested, and a first index corresponding to each target feature structure; the target feature structure is a feature structure with an index out-of-bounds risk;

[0019] A second index acquisition module, used to acquire at least one out-of-bounds protection structure included in the code to be tested, and acquire a second index corresponding to each out-of-bounds protection structure;

[0020] A structure association building module, used for acquiring an association relationship between each of the target feature structures and each of the cross-boundary protection structures based on each of the first indexes and each of the second indexes;

[0021] The index out-of-bounds test module is used to obtain the index out-of-bounds test results of each target feature structure in the code to be tested according to the association relationship.

[0022] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described in any one of the embodiments of the first aspect when executing the computer program.

[0023] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of the embodiments of the first aspect.

[0024] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method described in any one of the embodiments of the first aspect.

[0025] The above-mentioned index out-of-bounds test method, device, computer equipment, computer-readable storage medium and computer program product obtain the code to be tested, and obtain at least one target feature structure contained in the code to be tested, and the first index corresponding to each target feature structure; the target feature structure is a feature structure with an index out-of-bounds risk; obtain at least one out-of-bounds protection structure contained in the code to be tested, and obtain the second index corresponding to each out-of-bounds protection structure; based on each first index and each second index, obtain the association relationship between each target feature structure and each out-of-bounds protection structure; according to the association relationship, obtain the index out-of-bounds test result of each target feature structure in the code to be tested. In this embodiment, by obtaining the code to be tested, the target feature structure in the code to be tested that may have an index out-of-bounds risk and the first index corresponding to the target feature structure can be obtained. The out-of-bounds protection structure contained in the code to be tested and the second index corresponding to the out-of-bounds protection structure can also be obtained. The first index and the second index can then be used to construct an association relationship between the target feature structure and the out-of-bounds protection structure in the code to be tested, thereby using the above association relationship to obtain the index out-of-bounds test results of each target feature structure in the code to be tested. In this way, the use of memory offsets or array out-of-bounds tests based on function call relationships can be avoided, thereby improving the scope of application of the index out-of-bounds test method. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0027] Figure 1 A schematic diagram of a flow chart of an index out-of-bounds testing method in one embodiment;

[0028] Figure 2 A schematic diagram of a process for obtaining an association relationship between a characteristic structure and a protection structure in one embodiment;

[0029] Figure 3 A schematic diagram of a flow chart of obtaining an index out-of-bounds test result of a target feature structure in one embodiment;

[0030] Figure 4 A schematic diagram of a flow chart of obtaining a target feature structure contained in a code to be tested in one embodiment;

[0031] Figure 5 A schematic diagram of a flow chart of a method index out-of-bounds test in one embodiment;

[0032] Figure 6A schematic diagram of a cross-border protection determination process in an embodiment;

[0033] Figure 7 A schematic diagram of the structure of an index out-of-bounds testing device in one embodiment;

[0034] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0035] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0036] In one embodiment, Figure 1 As shown, an index out-of-bounds test method is provided. This embodiment uses the method applied to a server as an example for illustration. It can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0037] Step S101, obtaining a code to be tested, and obtaining at least one target feature structure contained in the code to be tested, and a first index corresponding to each target feature structure; the target feature structure is a feature structure with a risk of index crossing the boundary.

[0038] Among them, the code to be tested refers to the application code that needs to be tested for index out-of-bounds, the target feature structure refers to the feature structure in the code to be tested that may cause the index out-of-bounds phenomenon, that is, the feature code structure that may have the risk of index out-of-bounds, and the first index refers to the index variable carried in the target feature structure. Since the target feature structure is a feature structure in the code to be tested that may have the risk of index out-of-bounds, the feature structure must carry an index variable, that is, the feature structure must carry the first index.

[0039] Specifically, when performing an index out-of-bounds test, the server can first use an automated testing tool to pull the code to be tested that needs to be tested for an index out-of-bounds test, and then scan the code to be tested through the scanning script in the automated testing tool, thereby identifying the various target feature structures contained in the code to be tested, as well as the index object carried by each target feature structure, as the first index corresponding to each target feature structure.

[0040] Step S102: obtaining at least one out-of-bounds protection structure included in the code to be tested, and obtaining a second index corresponding to each out-of-bounds protection structure.

[0041] The out-of-bounds protection structure refers to the code structure in the code to be tested that is used to protect against the risk of index out-of-bounds. Generally speaking, in order to prevent the index from going out of bounds, the index is usually required to meet the following conditions: the index is greater than 0 and the index is less than the length of the indexed object. Therefore, the code structure in the code to be tested that is used to ensure that the index is greater than 0 and the index is less than the length of the indexed object can be used as an out-of-bounds protection structure. The second index refers to the index variable carried in the out-of-bounds protection structure. Since the out-of-bounds protection structure is used to ensure that the index meets the conditions that the index is greater than 0 and the index is less than the length of the indexed object, the out-of-bounds protection structure must also carry an index variable.

[0042] Specifically, after obtaining the code to be tested, similar to the acquisition of the target feature structure, the server can also identify the various out-of-bounds protection structures contained in the code to be tested and the index objects carried by each out-of-bounds protection structure through the scanning script in the automated testing tool as the second index corresponding to each out-of-bounds protection structure.

[0043] Step S103, based on each first index and each second index, obtaining the association relationship between each target feature structure and each cross-boundary protection structure;

[0044] Step S104, obtaining the index out-of-bounds test result of each target feature structure in the code to be tested according to the association relationship.

[0045] The association relationship refers to the association between the target feature structure and the cross-boundary protection structure. The association relationship can be one-to-one, that is, one target feature structure is associated with one cross-boundary protection structure, or one-to-many, that is, one target feature structure is associated with multiple cross-boundary protection structures. If there is an association relationship between a target feature structure and a cross-boundary protection structure, it means that the cross-boundary protection structure is used to avoid index cross-boundary phenomenon when the target feature structure is running.

[0046] Specifically, after the server obtains the first index corresponding to each target feature structure and the second index corresponding to each out-of-bounds protection structure, it can use the above indexes to obtain the association relationship between each target feature structure and each out-of-bounds protection structure. For example, when the first index and the second index are the same, the association relationship between the target feature structure corresponding to the first index and the out-of-bounds protection structure corresponding to the second index can be constructed. Afterwards, the index out-of-bounds test result of each target feature structure can be obtained based on the above-constructed association relationship. For example, the out-of-bounds protection structure associated with a target feature structure can be used to ensure that the first index in the target feature structure is greater than 0 and less than the length of the indexed object, then it can be said that the index out-of-bounds test result of the target feature structure is a passed test.

[0047] In the above-mentioned index out-of-bounds test method, the code to be tested is obtained, and at least one target feature structure contained in the code to be tested and a first index corresponding to each target feature structure are obtained; the target feature structure is a feature structure with an index out-of-bounds risk; at least one out-of-bounds protection structure contained in the code to be tested is obtained, and a second index corresponding to each out-of-bounds protection structure is obtained; based on each first index and each second index, an association relationship between each target feature structure and each out-of-bounds protection structure is obtained; based on the association relationship, an index out-of-bounds test result of each target feature structure in the code to be tested is obtained. In this embodiment, by obtaining the code to be tested, the target feature structure in the code to be tested that may have an index out-of-bounds risk and the first index corresponding to the target feature structure can be obtained. The out-of-bounds protection structure contained in the code to be tested and the second index corresponding to the out-of-bounds protection structure can also be obtained. The first index and the second index can then be used to construct an association relationship between the target feature structure and the out-of-bounds protection structure in the code to be tested, thereby using the above association relationship to obtain the index out-of-bounds test results of each target feature structure in the code to be tested. In this way, the use of memory offsets or array out-of-bounds tests based on function call relationships can be avoided, thereby improving the scope of application of the index out-of-bounds test method.

[0048] In one embodiment, if Figure 2 As shown, step S103 may further include:

[0049] Step S201, obtaining a current first index and a current target feature structure corresponding to the current first index; the current first index is any one of the first indexes.

[0050] The current first index refers to any one of the first indexes, and the current target feature structure refers to the target feature structure corresponding to the current first index, that is, the target feature structure carrying the current first index. Specifically, after obtaining each first index, the server can use each first index as the current first index, thereby further obtaining the target feature structure corresponding to the current first index as the current target feature structure.

[0051] Step S202: if there is a current second index matching the current first index in each second index, obtain a current cross-border protection structure corresponding to the current second index;

[0052] Step S203: constructing an association relationship between the current target feature structure and the current cross-border protection structure.

[0053] The current second index refers to the second index that matches the current first index, and the current cross-border protection structure refers to the cross-border protection structure corresponding to the current second index, that is, the cross-border protection structure carrying the current second index. Specifically, after obtaining the current first index, the server can match the current first index with each second index. If there is a current second index that matches the current first index in the second index, the cross-border protection structure corresponding to the current second index can be further obtained as the current cross-border protection structure, thereby constructing the association relationship between the current target feature structure and the current cross-border protection structure. The above process can be used to construct the association relationship between each target feature structure and the cross-border protection structure.

[0054] In this embodiment, the server can also identify the current second index matched by each current first index, thereby constructing an association relationship between the current target feature structure corresponding to the current first index and the current cross-boundary protection structure corresponding to the current second index. In this way, the efficiency of building the association relationship can be improved.

[0055] In addition, after step S201, it may also include: when any second index satisfies the preset matching conditions, the second index is used as the current second index that matches the current first index; the preset matching conditions include: the out-of-bounds protection structure corresponding to the second index and the current target feature structure are located in the same function method; the index identifier corresponding to the second index is the same as the index identifier corresponding to the current first index; the number of code lines where the second index is located is before the number of code lines where the current first index is located.

[0056] The preset matching condition refers to a pre-set condition that characterizes the matching of the first index and the second index. If a second index and the first index meet the above matching condition, it means that the second index matches the first index. The preset matching condition may include the following three items: (1) The out-of-bounds protection structure corresponding to the second index and the current target feature structure are located in the same function method, that is, the current target feature structure and the out-of-bounds protection structure corresponding to the second index are within the same method implementation; (2) The index identifier corresponding to the second index is the same as the index identifier corresponding to the current first index. The index identifier can be the unique id of the AST structure corresponding to the index variable, that is, the unique id of the AST structure corresponding to the second index is the same as the unique id of the AST structure corresponding to the current first index; (3) The number of lines of code where the second index is located is before the number of lines of code where the current first index is located, that is, the line number of the second index in the out-of-bounds protection structure is less than or equal to the line number of the first index in the target feature structure. Through the above comparison conditions, if a second index and the current first index meet the above preset matching conditions, the second index can be used as the current second index that matches the current first index.

[0057] In this embodiment, the current second index that matches the current first index can also be filtered out according to the following conditions: the out-of-bounds protection structure and the target feature structure are located in the same function method, the second index has the same index identifier as the first index, and the number of code lines where the second index is located is before the first index. Only when the above conditions are met will the second index be used as the current second index. In this way, the accuracy of the current second index screening can be improved.

[0058] Furthermore, if Figure 3 As shown, step S104 may further include:

[0059] Step S301: when the association relationship includes the association relationship between the current target feature structure and the current cross-border protection structure, obtain the index attribute of the current first index and the structure attribute of the current cross-border protection structure.

[0060] The index attribute refers to the attribute information related to the current first index, and the structural attribute may be the attribute information related to the current cross-boundary protection structure. The above attribute information can be identified based on pre-set rules. Specifically, if there is an association between the current target feature structure and the current cross-boundary protection structure, the server can further identify the index attribute of the current first index corresponding to the current target feature structure and the structural attribute of the current cross-boundary protection structure based on the preset rules.

[0061] Step S302, when the structure attribute matches the index attribute, determining that the index out-of-bounds test result of the current target feature structure is a test pass;

[0062] Step S303: when the structure attribute does not match the index attribute, determining that the index out-of-bounds test result of the current target feature structure is a test failure.

[0063] Afterwards, the structural attributes and index attributes can be judged to match each other based on the structural attributes and index attributes. The matching rules for the structural attributes and index attributes can also be set in advance in the server. If the structural attributes match the index attributes, it means that the current out-of-bounds protection structure can meet the out-of-bounds protection requirements for the current target feature structure. Therefore, the index out-of-bounds test result of the current target feature structure is that the test passed.

[0064] If the structure attribute does not match the index attribute, it means that although the current target feature structure has an associated current out-of-bounds protection structure, the associated current out-of-bounds protection structure cannot meet the out-of-bounds protection requirements for the current target feature structure. For example, the associated current out-of-bounds protection structure can only ensure that the first index in the current target feature structure is greater than 0, but cannot ensure that the first index is less than the length of the indexed object. In this case, the index out-of-bounds test result of the current target feature structure is test failure.

[0065] In this embodiment, if there is an association relationship between the current target feature structure and the current out-of-bounds protection structure, the server can further obtain the index attribute of the current first index corresponding to the current target feature structure, and the structural attribute of the current out-of-bounds protection structure, so as to judge whether the index attribute matches the structural attribute according to the pre-built matching rules. If they match, the index out-of-bounds test result of the current target feature structure is determined to be a passed test, otherwise a failed test. In this way, the accuracy of the index out-of-bounds test can be improved.

[0066] Further, the index attribute includes a first index attribute and a second index attribute, and the structure attribute includes a first structure attribute, a second structure attribute and a third structure attribute; the first index attribute represents that there is an attribute restriction condition for the first index that is always greater than 0, and the second index attribute represents that there is no attribute restriction condition for the first index; the first structure attribute represents that the cross-boundary protection structure is used to determine whether the first index is greater than 0, the second structure attribute represents that the cross-boundary protection structure is used to determine whether the first index is less than the length of the indexed object, and the third structure attribute represents that the cross-boundary protection structure is used to determine whether the first index is greater than 0 and whether the first index is less than the length of the indexed object; after step S301, it may also include: when the index attribute is the first index attribute, if the structure attribute of the current cross-boundary protection structure is the second structure attribute or the third structure attribute, then it is determined that the structure attribute matches the index attribute; when the index attribute is the second index attribute, if the structure attribute of the current cross-boundary protection structure is the third structure attribute, or the structure attribute of the current cross-boundary protection structure includes both the first structure attribute and the second structure attribute, then it is determined that the structure attribute matches the index attribute.

[0067] In this embodiment, there are two types of index attributes, namely the first index attribute and the second index attribute, wherein the first index attribute represents that a certain first index has an attribute restriction condition that is always greater than 0, while the second index attribute represents that a certain first index does not have the above attribute restriction condition. In this embodiment, when declaring and assigning values, some index variables can be restricted by attributes to have the prerequisite of not being a negative number, that is, there is an attribute restriction condition that is always greater than 0. For this type of index, the out-of-bounds protection judgment only needs to continue to compare whether the polyphonic sound is less than the length of the indexed object. Therefore, different index types can be distinguished by index attributes. If the index attribute of the current first index is the first index attribute, it means that the current first index has the prerequisite of not being a negative number. If the index attribute of the current first index is the second index attribute, it means that the current first index does not have the prerequisite of not being a negative number.

[0068] Similarly, there are three types of structural attributes, namely the first structural attribute, the second structural attribute and the third structural attribute, where the first structural attribute represents that a certain out-of-bounds protection structure is only used to determine whether the first index is greater than 0, the second structural attribute represents that a certain out-of-bounds protection structure is used to determine whether the first index is less than the length of the indexed object, and the third structural attribute represents that the out-of-bounds protection structure can be used to determine whether the first index is greater than 0 and whether the first index is less than the length of the indexed object. For example, if a certain out-of-bounds protection structure is a comparison of an index and a number in an if condition, the out-of-bounds protection structure can be equivalent to determining whether the first index is greater than 0, and its corresponding structural attribute can be the first structural attribute. If a certain out-of-bounds protection structure is a comparison of an index and an index object length in an if condition, the out-of-bounds protection structure can be equivalent to determining whether the first index is less than the length of the indexed object, and its corresponding structural attribute can be the second structural attribute.

[0069] Specifically, if the index attribute of the current first index is the first index attribute, it indicates that the current first index has an attribute restriction condition that is always greater than 0. Therefore, the out-of-bounds protection judgment only needs to continue to compare whether the index is less than the length of the indexed object, that is, it only needs the structural attribute of the current out-of-bounds protection structure associated with the current target feature structure to be the second structural attribute or the third structural attribute, that is, the structural attribute and the index attribute match.

[0070] If the index attribute of the current first index is the second index attribute, it indicates that the current first index does not have an attribute restriction condition that is always greater than 0. Therefore, the out-of-bounds protection judgment needs to compare whether the index is greater than 0 and whether the index is less than the length of the indexed object. Therefore, the structural attribute of the current out-of-bounds protection structure associated with the current target feature structure needs to be the third structural attribute, or the structural attribute of the current out-of-bounds protection structure can include the first structural attribute and the second structural attribute at the same time. For example, the associated current out-of-bounds protection structure can be two structures, one out-of-bounds protection structure is used to compare whether the index is greater than 0, and the other out-of-bounds protection structure is used to compare whether the index is less than the length of the indexed object. In this case, the structural attributes of the current out-of-bounds protection structure can be two types, namely the first structural attribute and the second structural attribute.

[0071] Specifically, if the index attribute of the current first index is the second index attribute, it indicates that the current first index does not have an attribute restriction condition that is always greater than 0. Therefore, the out-of-bounds protection judgment needs to compare whether the index is greater than 0 and whether the index is less than the length of the indexed object. That is, the structural attribute of the current out-of-bounds protection structure associated with the current target feature structure must be the third structural attribute, or the structural attribute of the current out-of-bounds protection structure must include both the first structural attribute and the second structural attribute to satisfy the matching of the structural attribute and the index attribute.

[0072] In this embodiment, if the index attribute of the current first index is the first index attribute, the structural attribute of the current cross-border protection structure only needs to be the second structural attribute or the third structural attribute to satisfy the matching of the structural attribute and the index attribute. If the index attribute of the current first index is the second index attribute, the structural attribute of the current cross-border protection structure needs to be the third structural attribute, or the structural attribute of the current cross-border protection structure needs to include both the first structural attribute and the second structural attribute to satisfy the matching of the structural attribute and the index attribute. In this way, the accuracy of the cross-border protection judgment can be improved.

[0073] In addition, after step S201, it may also include: when there is no current second index matching the current first index in each second index, determining that there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested; step S104 may further include: when there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested, determining that the index out-of-bounds test result of the current target feature structure is a test failure.

[0074] However, if all the second indexes do not match the current first index, that is, there is no current second index matching the current first index among the second indexes, then it indicates that there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested. In this case, it indicates that there is no out-of-bounds protection structure for the current target feature structure in the code to be tested, that is, there is no out-of-bounds protection for the current target feature structure. Therefore, the index out-of-bounds test result of the current target feature structure is test failure.

[0075] In this embodiment, if there is no current second index in the second index that matches the current first index, it indicates that there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested. Therefore, the index out-of-bounds test result of the current target feature structure is test failure. This method can improve the integrity of the index out-of-bounds test.

[0076] In one embodiment, Figure 4 As shown, step S101 may further include:

[0077] Step S401, obtaining a preset target feature structure rule table; the target feature structure rule table stores target method names corresponding to each target feature structure, and target object types of calling objects that call each feature structure.

[0078] The target feature structure rule table is a rule table for storing target structure features. The rule table can be constructed by collecting the method names of feature structures in the project history that caused the application to crash when the index exceeded the length boundary of the indexed object. If a certain structure feature hits a table item in the target feature structure rule table, then it means that the structure feature is the target structure feature. The target feature structure rule table can be pre-stored with the feature method names corresponding to each target feature structure, that is, the target method name, and the object type of the calling object that calls each feature structure, that is, the target object type.

[0079] For example, the target feature structure rule table can be shown as Table 1. In the first row of Table 1, it indicates that the target method name corresponding to a certain target feature structure is "objectAtindex:", and the target object type of the calling object that calls the target feature structure is a variable array type. Similarly, in the second row of Table 1, it indicates that the target method name corresponding to a certain target feature structure is "insertObject:atlndex:", and the target object type of the calling object that calls the target feature structure is a variable array type.

[0080] Table 1 Target feature structure rule table

[0081]

[0082] Step S402, obtaining the method name of each feature structure contained in the code to be tested, and the object type of the calling object that calls each feature structure;

[0083] Step S403: When the method name of any feature structure matches the target method name stored in the target feature structure rule table, and the object type matches the target object type corresponding to the target method name, the feature structure is determined to be the target feature structure.

[0084] After obtaining the target feature structure rule table, the server can further use the target feature structure rule table to identify the target feature structure contained in the code to be tested. The specific process is to first obtain the method names of each feature structure contained in the code to be tested, and the object type of the calling object that calls the above feature structure. If the method name of a feature structure hits the target method name stored in the target feature structure rule table, that is, the method name of the feature structure matches the target method name, and at the same time, the object type of the calling object that calls the feature structure hits the target object type corresponding to the target method name, that is, the object type matches the target object type corresponding to the target method name, then it means that the feature structure is the target feature structure. For example, the code to be tested contains an object of a variable array type that calls a feature structure with a method name of "objectAtindex:", and at this time, the first row of the target feature structure rule table is hit, so the feature structure is the target feature structure.

[0085] In this embodiment, a target feature structure rule table may be pre-constructed, so as to use the target feature structure rule table to identify the target feature structure of the code to be tested, thereby realizing target feature structure identification for static code and improving the accuracy of target feature structure identification.

[0086] In one embodiment, step S102 may further include: obtaining a pre-set out-of-bounds protection structure rule table; the out-of-bounds protection structure rule table stores code writing rules for each out-of-bounds protection structure; when any sub-code structure in the code to be tested satisfies any code writing rule stored in the out-of-bounds protection structure rule table, determining that the sub-code structure is an out-of-bounds protection structure contained in the code to be tested.

[0087] The out-of-bounds protection structure rule table is a table used to store the code writing rules of the out-of-bounds protection structure. Since there are many ways to write the out-of-bounds protection structure in the actual code writing process, it is possible to collect various code writing methods of the out-of-bounds protection structure in advance, divide the various code writing methods into equivalents, and sort them out to obtain the out-of-bounds protection structure rule table. The sub-code structure refers to the code structure that constitutes the code to be tested. The code to be tested can be composed of multiple code structures, and each code structure is a sub-code structure.

[0088] Specifically, the server can store a pre-built out-of-bounds protection structure rule table, which can store code writing rules for each out-of-bounds protection structure. If a sub-code structure in the code to be tested conforms to the code writing rules of a certain out-of-bounds protection structure in the out-of-bounds protection structure rule table, it means that the sub-code structure may be an out-of-bounds protection structure contained in the code to be tested.

[0089] For example, the rule table of the out-of-bounds protection structure can be shown in Table 2. The first row in Table 2 indicates that the code writing rule corresponding to a certain out-of-bounds protection structure is that there is an index and a number in the if condition for comparison. This code structure can be used to determine whether the index is greater than 0, which belongs to the first type of out-of-bounds protection structure. Similarly, the second row in Table 2 indicates that the code writing rule corresponding to a certain out-of-bounds protection structure is that the index and the length of the index object are compared in the if condition. This code structure can be used to determine whether the index is less than the length of the indexed object, which belongs to the second type of out-of-bounds protection structure. The fifth row in Table 2 indicates that the code writing rule corresponding to a certain out-of-bounds protection structure is that the index and the pre-assigned MIN macro definition are compared. This code structure can be used to determine whether the index is greater than 0, and can also be used to determine whether the index is less than the length of the indexed object, which belongs to the third type of out-of-bounds protection structure.

[0090] Table 2 Cross-border protection structure rules

[0091]

[0092] In this embodiment, an out-of-bounds protection structure rule table can also be pre-constructed, so that the out-of-bounds protection structure of the code to be tested can be identified using the out-of-bounds protection structure rule table, thereby realizing out-of-bounds protection structure identification for static code and improving the accuracy of out-of-bounds protection structure identification.

[0093] In one embodiment, a method index out-of-bounds crash static scanning method is also provided, which can accurately and quickly identify potential method index out-of-bounds crashes in iOS projects, and covers a wider range of data types, including arrays and strings, as well as other data types that use methods to set / get index values. This method first collects feature methods that will cause crashes when the index exceeds the length boundary of the indexed object, and then uses the WCClangMatcher static scanning tool to obtain the code structure that calls the feature method, and the out-of-bounds protection structure of the input object index that exists before the feature method (index is greater than 0 and less than the length of the indexed object). If there is an index out-of-bounds protection structure before the feature method, it is considered that the feature structure has no risk of out-of-bounds crash, otherwise, there is a risk of out-of-bounds crash.

[0094] like Figure 5 As shown in the figure, users can first upload the static scanning rule project to the git repository, then configure the pipeline, add the target project code automatic pull and code submission notification plug-in, trigger the static scan according to the code submission, and the scan result will be automatically submitted and notified to the test executor after the task is completed. The specific implementation process may include the following steps:

[0095] (1) Collection feature method.

[0096] According to the historical crash problems of the project, the method names that will cause crash when the index exceeds the length boundary of the indexed object are collected. The collected feature methods are shown in Table 1.

[0097] (2) Collect out-of-bounds protection code writing methods.

[0098] Index out-of-bounds protection must meet two conditions at the same time: 1. index is greater than 0; 2. index is less than the length of the indexed object. In actual code writing, there are many ways to write these two conditions. After being divided into equivalence classes, they are summarized as shown in Table 2.

[0099] (3) Classify the feature structure according to the variable attributes of index index.

[0100] When declaring and assigning values, some index variables are restricted by attributes to ensure that they are not negative numbers. The out-of-bounds protection judgment of such indexes only needs to continue to compare whether the index is less than the length of the indexed object. The specific variable attribute classification can be shown in Table 3.

[0101] Table 3 Schematic diagram of variable attribute classification

[0102]

[0103] (4) Compare the data and identify the problem points.

[0104] Since the matching of the feature structure and the cross-border protection structure is independent of each other, when comparing data, the consistency judgment of the index variables in the feature structure and the cross-border protection structure must meet the following conditions at the same time:

[0105] 1. Inside the same method implementation;

[0106] 2. The unique id of the AST structure corresponding to the index variable is the same;

[0107] 3. The row number of index in the out-of-bounds protection structure is less than or equal to the row number of index in the feature structure.

[0108] In this embodiment, the feature structure whose index has a non-negative attribute may be named feature structure 1, and otherwise named feature structure 2.

[0109] Combined with the classification in (2), such as Figure 6 As shown, the cross-border protection judgment rules are as follows:

[0110] 1. For all feature structures, when protection condition 3 (a combination of protection conditions 1 and 2) exists, there is out-of-bounds protection;

[0111] 2. For feature structure 1, when protection condition 2 exists, there is out-of-bounds protection;

[0112] 3. For feature structure 2, when protection condition 1 and protection condition 2 exist, there is out-of-bounds protection;

[0113] Finally, the problem structure can be obtained by identifying the parts without cross-border protection from all feature structures.

[0114] Through this embodiment, a static scanning method for method index out-of-bounds crash problems without data type restrictions is provided. The code structure that calls the feature method is used as the risk structure (the feature method can be added according to the actual situation of the project). The out-of-bounds protection structure of the index index, the input parameter object of the called feature method, is searched inside the same method implementation. By comparing the consistency of the variable index in the out-of-bounds protection structure and the risk structure, potential out-of-bounds crash risks can be discovered. It can also be based on static code analysis, which is time-saving and convenient for checking incremental submissions at any time. Potential problems can also be discovered in advance.

[0115] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0116] Based on the same inventive concept, the embodiment of the present application also provides an index out-of-bounds test device for implementing the above-mentioned index out-of-bounds test method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in the one or more index out-of-bounds test device embodiments provided below can refer to the limitations of the index out-of-bounds test method above, and will not be repeated here.

[0117] In one embodiment, Figure 7 As shown, an index out-of-bounds test device is provided, comprising: a first index acquisition module 701, a second index acquisition module 702, a structure association construction module 703 and an index out-of-bounds test module 704, wherein:

[0118] The first index acquisition module 701 is used to acquire the code to be tested, and acquire at least one target feature structure contained in the code to be tested, and a first index corresponding to each target feature structure; the target feature structure is a feature structure with an index out-of-bounds risk;

[0119] A second index obtaining module 702 is used to obtain at least one out-of-bounds protection structure included in the code to be tested, and obtain a second index corresponding to each out-of-bounds protection structure;

[0120] A structure association building module 703 is used to obtain the association relationship between each target characteristic structure and each cross-border protection structure based on each first index and each second index;

[0121] The index out-of-bounds test module 704 is used to obtain the index out-of-bounds test results of each target feature structure in the code to be tested according to the association relationship.

[0122] Each module in the above-mentioned index out-of-bounds test device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0123] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store code data to be tested. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an index out-of-bounds test method is implemented.

[0124] Those skilled in the art will understand that Figure 8The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0125] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.

[0126] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0127] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0128] 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 relevant regulations.

[0129] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0130] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0131] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. An index out-of-bounds testing method, characterized in that: The method comprises: Acquire the code to be tested, and acquire at least one target feature structure contained in the code to be tested, and a first index corresponding to each target feature structure; the target feature structure is a feature structure with a risk of index crossing the boundary; Obtain at least one out-of-bounds protection structure included in the code to be tested, and obtain a second index corresponding to each of the out-of-bounds protection structures; Based on each of the first indexes and each of the second indexes, acquiring an association relationship between each of the target feature structures and each of the cross-boundary protection structures; According to the association relationship, an index out-of-bounds test result of each target feature structure in the code to be tested is obtained.

2. The method according to claim 1, characterized in that The acquiring, based on each of the first indexes and each of the second indexes, an association relationship between each of the target feature structures and each of the cross-boundary protection structures includes: Obtaining a current first index and a current target feature structure corresponding to the current first index; the current first index is any one of the first indexes; When there is a current second index matching the current first index in each of the second indexes, obtaining a current cross-border protection structure corresponding to the current second index; An association relationship between the current target feature structure and the current cross-boundary protection structure is established.

3. The method according to claim 2, characterized in that After obtaining the current first index and the current target feature structure corresponding to the current first index, the method further includes: In the case where any of the second indexes meets a preset matching condition, taking the second index as a current second index that matches the current first index; The preset matching conditions include: The out-of-bounds protection structure corresponding to the second index and the current target feature structure are located in the same function method; The index identifier corresponding to the second index is the same as the index identifier corresponding to the current first index; The code line number where the second index is located is located before the code line number where the current first index is located.

4. The method according to claim 2, characterized in that: The step of obtaining the index out-of-bounds test result of each target feature structure in the code to be tested according to the association relationship includes: In a case where the association relationship includes an association relationship between the current target feature structure and the current cross-border protection structure, obtaining an index attribute of the current first index and a structure attribute of the current cross-border protection structure; In the case where the structure attribute matches the index attribute, determining that the index out-of-bounds test result of the current target feature structure is a test pass; In the case where the structure attribute does not match the index attribute, it is determined that the index out-of-bounds test result of the current target feature structure is a test failure.

5. The method according to claim 4, characterized in that The index attribute includes a first index attribute and a second index attribute, and the structure attribute includes a first structure attribute, a second structure attribute and a third structure attribute; the first index attribute indicates that the first index has a property restriction condition that is always greater than 0, and the second index attribute indicates that the first index does not have the property restriction condition; The first structure attribute represents that the out-of-bounds protection structure is used to determine whether the first index is greater than 0, the second structure attribute represents that the out-of-bounds protection structure is used to determine whether the first index is less than the length of the indexed object, and the third structure attribute represents that the out-of-bounds protection structure is used to determine whether the first index is greater than 0 and whether the first index is less than the length of the indexed object; After acquiring the index attribute of the current first index and the structure attribute of the current cross-border protection structure, the method further includes: In a case where the index attribute is the first index attribute, if the structure attribute of the current cross-boundary protection structure is the second structure attribute or the third structure attribute, determining that the structure attribute matches the index attribute; When the index attribute is the second index attribute, if the structure attribute of the current cross-border protection structure is the third structure attribute, or the structure attribute of the current cross-border protection structure includes both the first structure attribute and the second structure attribute, it is determined that the structure attribute matches the index attribute.

6. The method according to any one of claims 2 to 4, characterized in that: After obtaining the current first index and the current target feature structure corresponding to the current first index, the method further includes: In the case that there is no current second index matching the current first index in each of the second indexes, determining that there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested; The step of obtaining the index out-of-bounds test result of each target feature structure in the code to be tested according to the association relationship includes: In the case that there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested, it is determined that the result of the index out-of-bounds test of the current target feature structure is a test failure.

7. The method according to claim 1, characterized in that The obtaining of at least one target feature structure contained in the code to be tested comprises: Obtaining a preset target feature structure rule table; the target feature structure rule table stores target method names corresponding to each target feature structure, and target object types of calling objects that call each of the feature structures; Obtaining the method name of each feature structure contained in the code to be tested, and the object type of the calling object that calls each feature structure; When the method name of any of the feature structures matches the target method name stored in the target feature structure rule table, and the object type matches the target object type corresponding to the target method name, the feature structure is determined to be the target feature structure.

8. The method according to claim 1, characterized in that The obtaining of at least one out-of-bounds protection structure included in the code to be tested includes: Obtaining a preset cross-border protection structure rule table; the cross-border protection structure rule table stores code writing rules for each cross-border protection structure; When any sub-code structure in the code to be tested satisfies any code writing rule stored in the out-of-bounds protection structure rule table, the sub-code structure is determined to be an out-of-bounds protection structure included in the code to be tested.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Array cross-border protection method, device and equipment and computer readable storage medium

    CN117742653A

  • Code testing method and device, equipment and storage medium

    CN118656292A

  • Method, device and equipment for generating basic software layer based on Autosar architecture

    CN118796177A

  • Dynamic arrays and overlays with bounds policies

    US20030014607A1