Index out-of-bounds testing method, computer device, and computer program product

By constructing the association between the target feature structure and the out-of-bounds protection structure in the code under test, the problem of the narrow applicability of existing index out-of-bounds testing methods is solved, and accurate detection of variable arrays in Objective-C is achieved.

CN119902979BActive Publication Date: 2025-12-05TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing index out-of-bounds testing methods have a narrow scope of application, cannot be applied to variable arrays in Objective-C, and do not provide comprehensive coverage.

Method used

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

Benefits of technology

This improves the applicability of the index out-of-bounds testing method, enabling more accurate detection of index out-of-bounds risks in variable arrays in Objective-C.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902979B_ABST
    Figure CN119902979B_ABST
Patent Text Reader

Abstract

The application relates to an index out-of-bound test method, a computer device and a computer program product. The method comprises the following steps: obtaining to-be-tested code, obtaining at least one target feature structure contained in the to-be-tested code, and obtaining first indexes corresponding to the target feature structures; the target feature structure is a feature structure with an index out-of-bound risk; obtaining at least one out-of-bound protection structure contained in the to-be-tested code, and obtaining second indexes corresponding to the out-of-bound protection structures; obtaining an association relationship between the target feature structures and the out-of-bound protection structures based on the first indexes and the second indexes; and obtaining an index out-of-bound test result of each target feature structure in the to-be-tested code according to the association relationship. The method can avoid using a memory offset or a function call relationship to implement array out-of-bound test, so that the application range of the index out-of-bound test method can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to an index out-of-bounds testing method, computer equipment, and computer program products. Background Technology

[0002] Index out of bounds occurs when an index beyond the actual range is used to access an array, string, or other collection data structure. This error can cause the program to crash. For example, if the index is less than 0 or greater than or equal to the length of the array or string when accessing it, an index out of bounds error will occur, leading to a program crash. Therefore, to avoid program crashes, it is usually necessary to perform index out of bounds tests on the application to ensure its stable operation.

[0003] Traditionally, index out-of-bounds testing can be performed in two main 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 compile-time calculation, which is unsuitable for dynamically computed Objective-C languages. Testing based on function call relationships is limited to immutable arrays, resulting in insufficient coverage. Furthermore, code out-of-bounds behavior in Objective-C typically does not involve function call relationships, and the length of mutable arrays in Objective-C cannot be calculated in static code, making these methods equally unsuitable. Therefore, existing index out-of-bounds testing methods are only applicable to code with specific data types, thus limiting their applicability. Summary of the Invention

[0004] Therefore, 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 applicability of the index out-of-bounds testing method in response to the above-mentioned technical problems.

[0005] Firstly, this application provides a method for index out-of-bounds testing, including:

[0006] Obtain the code to be tested, and obtain 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 the risk of index out of bounds.

[0007] 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;

[0008] Based on each of the first indexes and each of the second indexes, the association relationship between each of the target feature structures and each of the boundary protection structures is obtained;

[0009] Based on the aforementioned association, the index out-of-bounds test results for each of the target feature structures in the code to be tested are obtained.

[0010] In one embodiment, obtaining the association between each target feature structure and each boundary crossing protection structure based on each first index and each second index 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 indices; if there is a current second index in each of the second indices that matches the current first index, obtaining the current boundary crossing protection structure corresponding to the current second index; and constructing the association between the current target feature structure and the current boundary crossing protection structure.

[0011] In one embodiment, after obtaining the current first index and the current target feature structure corresponding to the current first index, the method further includes: if any second index 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 boundary 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; and the line number of the code where the second index is located is located before the line number of the code where the current first index is located.

[0012] In one embodiment, obtaining the index out-of-bounds test result of each target feature structure in the code to be tested based on the association relationship includes: when the association relationship includes an 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 test pass; 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 test fail.

[0013] In one embodiment, the index attribute includes a first index attribute and a second index attribute, and the structural attribute includes a first structural attribute, a second structural attribute, and a third structural attribute; the first index attribute indicates that the first index has an attribute constraint condition that is always greater than 0, and the second index attribute indicates that the first index does not have the attribute constraint condition; the first structural attribute indicates that the boundary protection structure is used to determine whether the first index is greater than 0, the second structural attribute indicates that the boundary protection structure is used to determine whether the first index is less than the length of the indexed object, and the third structural attribute indicates that the boundary protection structure is used to determine both 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 structural attribute of the current boundary protection structure, the method further includes: if the index attribute is the first index attribute, and the structural attribute of the current boundary protection structure is the second structural attribute or the third structural attribute, then the structural attribute matches the index attribute; if the index attribute is the second index attribute, and the structural attribute of the current boundary protection structure is the third structural attribute, or the structural attribute of the current boundary protection structure simultaneously includes the first structural attribute and the second structural attribute, then the structural attribute matches the index attribute.

[0014] In one embodiment, after obtaining the current first index and the current target feature structure corresponding to the current first index, the method further includes: if there is no current second index matching the current first index in each of the second indices, determining that there is no out-of-bounds protection structure associated with the current target feature structure in the code to be tested; and obtaining the index out-of-bounds test result of each target feature structure in the code to be tested according to the association relationship, including: if 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 embodiment, obtaining at least one target feature structure contained in the code to be tested includes: obtaining a pre-set target feature structure rule table; the target feature structure rule table stores the target method name corresponding to each target feature structure, and the target object type of the calling object that calls each feature structure; 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; if 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, then the feature structure is determined to be the target feature structure.

[0016] In one embodiment, obtaining at least one boundary protection structure contained in the code to be tested includes: obtaining a pre-set boundary protection structure rule table; the boundary protection structure rule table stores the code writing rules for each boundary protection structure; and determining that any sub-code structure in the code to be tested is a boundary protection structure contained in the code to be tested if any code writing rule stored in the boundary protection structure rule table is satisfied.

[0017] Secondly, this application also provides an index out-of-bounds testing apparatus, comprising:

[0018] The first index acquisition module is used to acquire the code to be tested, and to 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 the risk of index out of bounds.

[0019] The second index acquisition module is used to acquire at least one out-of-bounds protection structure contained in the code to be tested, and to acquire the second index corresponding to each out-of-bounds protection structure.

[0020] The structure association construction module is used to obtain the association relationship between each target feature structure and each boundary protection structure based on each of the first index and each of the second index;

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

[0022] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described in any embodiment of the first aspect.

[0023] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in any embodiment of the first aspect.

[0024] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the method described in any embodiment of the first aspect.

[0025] The aforementioned index out-of-bounds testing method, apparatus, computer equipment, computer-readable storage medium, and computer program product 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 index out-of-bounds risk; acquire at least one out-of-bounds protection structure contained in the code to be tested, and acquire a second index corresponding to each out-of-bounds protection structure; based on each first index and each second index, acquire the association relationship between each target feature structure and each out-of-bounds protection structure; and obtain the index out-of-bounds test result of each target feature structure in the code to be tested according to the association relationship. In this embodiment, by obtaining the code to be tested, the target feature structure that may have index out-of-bounds risk in the code to be tested, as well as 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, as well as the second index corresponding to the out-of-bounds protection structure, can also be obtained. Then, the first index and the second index can be used to construct the association relationship between the target feature structure and the out-of-bounds protection structure in the code to be tested. The index out-of-bounds test results of each target feature structure in the code to be tested can be obtained by using the above association relationship. This method can avoid using memory offsets or function call relationships to implement array out-of-bounds testing, thereby improving the applicability of the index out-of-bounds testing method. Attached Figure Description

[0026] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 This is a flowchart illustrating an index out-of-bounds test method in one embodiment;

[0028] Figure 2 This is a flowchart illustrating the process of obtaining the association between the feature structure and the protection structure in one embodiment;

[0029] Figure 3 This is a flowchart illustrating the process of obtaining the index out-of-bounds test results of the target feature structure in one embodiment;

[0030] Figure 4 This is a flowchart illustrating the process of obtaining the target feature structure contained in the code to be tested in one embodiment;

[0031] Figure 5 This is a flowchart illustrating a method index out-of-bounds test in one embodiment.

[0032] Figure 6This is a schematic diagram of the boundary protection determination process in one embodiment;

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

[0034] Figure 8 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0035] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0036] In one embodiment, such as Figure 1 As shown, an index out-of-bounds testing method is provided. This embodiment illustrates the method by applying it to a server. It is understood that this method can also be applied to a terminal, and further to a system including both a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:

[0037] Step S101: Obtain the code to be tested, and obtain at least one target feature structure contained in the code to be tested, as well as the first index corresponding to each target feature structure; the target feature structure is a feature structure with the risk of index out of bounds.

[0038] Here, 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 index out of bounds, that is, the feature code structure that may have the risk of index out of bounds. The first index refers to the index variable carried in the target feature structure. Since the target feature structure is the feature structure in the code to be tested that may have the risk of index out of bounds, it must carry an index variable, that is, it must carry a first index.

[0039] Specifically, when performing index out-of-bounds testing, the server can first use an automated testing tool to retrieve the code to be tested. Then, the scanning script in the automated testing tool can scan the code to be tested to identify the various target feature structures contained in the code to be tested, as well as the index object carried by each target feature structure, which serves as the first index corresponding to each target feature structure.

[0040] Step S102: 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.

[0041] Out-of-bounds protection structures refer to the code structures in the code under test used to protect against the risk of indexes going out of bounds. Generally, to prevent indexes from going out of bounds, the indexes usually need 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 structures in the code under test 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 out-of-bounds protection structures. 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 of the index being greater than 0 and the index being less than the length of the indexed object, the out-of-bounds protection structure must also carry index variables.

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

[0043] Step S103: Based on each first index and each second index, obtain the association relationship between each target feature structure and each boundary protection structure;

[0044] Step S104: Based on the association relationship, obtain the index out-of-bounds test results of each target feature structure in the code to be tested.

[0045] The association relationship refers to the association between the target feature structure and the boundary protection structure. This association relationship can be one-to-one, that is, one target feature structure is associated with one boundary protection structure, or it can be one-to-many, that is, one target feature structure is associated with multiple boundary protection structures. If there is an association relationship between a target feature structure and a boundary protection structure, it means that the boundary protection structure is used to avoid the index out-of-bounds phenomenon that occurs 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 boundary protection structure, it can use these indexes to obtain the association relationship between each target feature structure and each boundary protection structure. For example, when the first index and the second index are the same, an association relationship can be constructed between the target feature structure corresponding to the first index and the boundary protection structure corresponding to the second index. Then, the boundary crossing test result for each target feature structure can be obtained based on the constructed association relationship. For example, if the boundary crossing protection structure associated with a certain 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 boundary crossing test result for that target feature structure is a pass.

[0047] In the above index out-of-bounds testing method, the following steps are taken: First, the code to be tested is obtained, along with at least one target feature structure contained within the code 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. Second, at least one out-of-bounds protection structure is obtained within the code to be tested, along with a second index corresponding to each out-of-bounds protection structure. Based on each first index and each second index, the association between each target feature structure and each out-of-bounds protection structure is obtained. Based on the association, the index out-of-bounds test results for each target feature structure in the code to be tested are obtained. In this embodiment, by obtaining the code to be tested, the target feature structure that may have index out-of-bounds risk in the code to be tested, as well as 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, as well as the second index corresponding to the out-of-bounds protection structure, can also be obtained. Then, the first index and the second index can be used to construct the association relationship between the target feature structure and the out-of-bounds protection structure in the code to be tested. The index out-of-bounds test results of each target feature structure in the code to be tested can be obtained by using the above association relationship. This method can avoid using memory offsets or function call relationships to implement array out-of-bounds testing, thereby improving the applicability of the index out-of-bounds testing method.

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

[0049] Step S201: Obtain the current first index and the current target feature structure corresponding to the current first index; the current first index is any one of the first indices.

[0050] The current first index refers to any one of the first indices, while 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 the server obtains each first index, it can use each first index as the current first index, thereby further obtaining the target feature structure corresponding to the current first index, which is then used as the current target feature structure.

[0051] Step S202: If there is a current second index that matches the current first index in each of the second indices, obtain the current out-of-bounds protection structure corresponding to the current second index;

[0052] Step S203: Construct the association between the current target feature structure and the current boundary protection structure.

[0053] The current second index refers to the second index that matches the current first index, while the current out-of-bounds protection structure refers to the out-of-bounds protection structure corresponding to the current second index, i.e., the out-of-bounds protection structure carrying the current second index. Specifically, after obtaining the current first index, the server can match the current first index with each of the second indices. If a current second index exists that matches the current first index, the out-of-bounds protection structure corresponding to that current second index can be further obtained as the current out-of-bounds protection structure, thereby establishing the association between the current target feature structure and the current out-of-bounds protection structure. Through the above process, the association between each target feature structure and the out-of-bounds protection structure can be established.

[0054] In this embodiment, the server can also identify the current second index matched by each current first index, thereby constructing the association between the current target feature structure corresponding to the current first index and the current out-of-bounds protection structure corresponding to the current second index. This method can improve the efficiency of association construction.

[0055] Additionally, after step S201, the method may further include: if any second index satisfies a preset matching condition, the second index is used as the current second index that matches the current first index; the preset matching condition includes: the boundary 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; and the line number of the code where the second index is located is located before the line number of the code where the current first index is located.

[0056] The preset matching conditions refer to the pre-defined conditions that represent the matching of the first index and the second index. If a second index and the first index meet the above matching conditions, it means that the second index matches the first index. The preset matching conditions may include the following three: (1) The boundary protection structure corresponding to the second index is located in the same function method as the current target feature structure, that is, the current target feature structure and the boundary protection structure corresponding to the second index are in 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 line number of the code where the second index is located is located before the line number of the code where the current first index is located, that is, the line number of the second index in the boundary 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 selected by the following conditions: the out-of-bounds protection structure and the target feature structure are located in the same function method, the index identifier of the second index is the same as that of the first index, and the line number of the code where the second index is located is before that of the first index. Only when the above conditions are met can the second index be used as the current second index. This method can improve the accuracy of the current second index selection.

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

[0059] Step S301: If the association relationship includes the association relationship between the current target feature structure and the current boundary protection structure, obtain the index attribute of the current first index and the structural attribute of the current boundary protection structure.

[0060] Index attributes refer to the attribute information related to the current first index, while structural attributes can be the attribute information related to the current boundary protection structure. The above attribute information can be identified based on pre-set rules. Specifically, if there is a relationship between the current target feature structure and the current boundary protection structure, the server can further identify the index attributes of the current first index corresponding to the current target feature structure and the structural attributes of the current boundary protection structure based on preset rules.

[0061] Step S302: If the structural attributes and index attributes match, determine the index out-of-bounds test result of the current target feature structure as a passed test.

[0062] Step S303: If the structural attributes and index attributes do not match, determine that the index out-of-bounds test result of the current target feature structure is a test failure.

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

[0064] If the structural attributes and index attributes do not match, 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 of the current target feature structure. For example, the associated current out-of-bounds protection structure can only guarantee that the first index in the current target feature structure is greater than 0, but cannot guarantee 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 that the test fails.

[0065] In this embodiment, if there is an association 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. Then, it can determine 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 pass; otherwise, it fails. This method can improve the accuracy of the index out-of-bounds test.

[0066] Further, the index attributes include a first index attribute and a second index attribute, and the structural attributes include a first structural attribute, a second structural attribute, and a third structural attribute; the first index attribute indicates that the first index has an attribute constraint condition that is always greater than 0, and the second index attribute indicates that the first index does not have an attribute constraint condition; the first structural attribute indicates that the boundary protection structure is used to determine whether the first index is greater than 0, the second structural attribute indicates that the boundary protection structure is used to determine whether the first index is less than the length of the indexed object, and the third structural attribute indicates that the boundary protection structure is used to determine both 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 further include: when the index attribute is the first index attribute, if the structural attribute of the current boundary protection structure is the second structural attribute or the third structural attribute, then it is determined that the structural attribute matches the index attribute; when the index attribute is the second index attribute, if the structural attribute of the current boundary protection structure is the third structural attribute, or the structural attribute of the current boundary protection structure simultaneously contains the first structural attribute and the second structural attribute, then it is determined that the structural attribute matches the index attribute.

[0067] In this embodiment, there are two types of index attributes: a first index attribute and a second index attribute. The first index attribute indicates that a certain first index has a constraint that is always greater than 0, while the second index attribute indicates that a certain first index does not have the aforementioned constraint. In this embodiment, some index variables can be declared and assigned values ​​with the prerequisite of being non-negative, i.e., having a constraint that is always greater than 0. For the out-of-bounds protection judgment of this type of index, it is only necessary to continue comparing whether the polyphony is less than the length of the indexed object. Therefore, different index types can be distinguished by index attributes. If the current first index has the first index attribute, it means that the current first index has the prerequisite of being non-negative. If the current first index has the second index attribute, it means that the current first index does not have the prerequisite of being non-negative.

[0068] Similarly, structural attributes include three types: the first structural attribute, the second structural attribute, and the third structural attribute. The first structural attribute indicates that a bounds protection structure is only used to determine if the first index is greater than 0. The second structural attribute indicates that a bounds protection structure is used to determine if the first index is less than the length of the indexed object. The third structural attribute indicates that a bounds protection structure can be used to determine both if the first index is greater than 0 and if the first index is less than the length of the indexed object. For example, if a bounds protection structure is a comparison between an index and a number in an if condition, this bounds protection structure can be equivalent to determining if the first index is greater than 0, and its corresponding structural attribute would be the first structural attribute. Conversely, if a bounds protection structure is a comparison between an index and the length of the indexed object in an if condition, this bounds protection structure can be equivalent to determining if the first index is less than the length of the indexed object, and its corresponding structural attribute would 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 boundary 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 that the structural attribute of the current boundary protection structure associated with the current target feature structure is the second structural attribute or the third structural attribute, which satisfies the matching of structural attribute and index attribute.

[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 contain both the first and second structural attributes. 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 attribute 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 means that the current first index does not have an attribute restriction condition that is always greater than 0. Therefore, the boundary 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 boundary protection structure associated with the current target feature structure needs to be the third structural attribute, or the structural attribute of the current boundary protection structure needs to contain both the first and second structural attributes to satisfy the matching of structural attributes and index attributes.

[0072] In this embodiment, if the index attribute of the current first index is the first index attribute, the structure attribute of the current boundary protection structure only needs to be the second structure attribute or the third structure attribute to satisfy the matching of the structure attribute and the index attribute. However, if the index attribute of the current first index is the second index attribute, the structure attribute of the current boundary protection structure needs to be the third structure attribute, or the structure attribute of the current boundary protection structure needs to contain both the first and second structure attributes to satisfy the matching of the structure attribute and the index attribute. This method can improve the accuracy of boundary protection determination.

[0073] Additionally, after step S201, the method may further include: if there is no current second index in each second index that matches the current first 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: if 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] If none of the second indices match the current first index, meaning there is no current second index that matches the current first index, then it indicates that there is no out-of-bounds protection structure associated with the current target feature structure in the code under test. In this case, it means that there is no out-of-bounds protection structure for the current target feature structure in the code under test, meaning that the current target feature structure does not have out-of-bounds protection. Therefore, the result of the index out-of-bounds test for the current target feature structure is that the test fails.

[0075] In this embodiment, if there is no current second index that matches the current first index in the second 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 that the test fails. This method can improve the completeness of the index out-of-bounds test.

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

[0077] Step S401: Obtain the pre-set target feature structure rule table; the target feature structure rule table stores the target method name corresponding to each target feature structure, and the target object type of the calling object that calls each feature structure.

[0078] The target feature structure rule table is a rule table used to store target structural features. This rule table can be constructed by collecting the method names of feature structures in the project history that caused the application to crash due to the index exceeding the length boundary of the indexed object. If a structural feature matches a table entry in the target feature structure rule table, then that structural feature is a target structural feature. This target feature structure rule table may pre-store the feature method names corresponding to each target feature structure (i.e., the target method names) and the object types of the calling objects that invoke each feature structure (i.e., the target object types).

[0079] For example, the target feature structure rule table can be as shown in 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 Rules Table

[0081]

[0082] Step S402: 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 each feature structure;

[0083] Step S403: If 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, then the feature structure is determined to be the target feature structure.

[0084] After obtaining the target feature structure rule table, the server can further utilize it to identify the target feature structures contained in the code under test. Specifically, it first obtains the method names of each feature structure contained in the code under test, and the object type of the calling object that invokes the aforementioned feature structures. If the method name of a feature structure matches the target method name stored in the target feature structure rule table (i.e., the method name of the feature structure matches the target method name), and simultaneously, the object type of the calling object that invokes the feature structure matches the target object type corresponding to the target method name (i.e., the object type matches the target object type corresponding to the target method name), then this feature structure is considered the target feature structure. For example, if the code under test contains a variable array type object that calls a feature structure with the method name "objectAtindex:", this matches the first row of the target feature structure rule table, therefore this feature structure is the target feature structure.

[0085] In this embodiment, a target feature structure rule table can be pre-constructed, and the target feature structure of the code to be tested can be identified by using the target feature structure rule table, thereby realizing the identification of target feature structure 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 boundary protection structure rule table; the boundary protection structure rule table stores the code writing rules for each boundary protection structure; and if any sub-code structure in the code to be tested satisfies any code writing rule stored in the boundary protection structure rule table, the sub-code structure is determined to be a boundary protection structure contained in the code to be tested.

[0087] The boundary protection structure rule table is a table used to store the coding rules for boundary protection structures. Since there are many ways to write boundary protection structures in actual coding, various coding methods for boundary protection structures can be collected in advance, categorized into equivalent methods, and organized to obtain the boundary protection structure rule table. Sub-code structures refer to the code structures that make up the code to be tested. The code to be tested can be composed of multiple code structures, each of which is considered a sub-code structure.

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

[0089] For example, the bounds access protection structure rule table is shown in Table 2. The first row of Table 2 indicates that the code writing rule for a certain bounds access protection structure is that the if condition contains an index and a number for comparison. This code structure can be used to determine if the index is greater than 0, belonging to the first type of bounds access protection structure. Similarly, the second row of Table 2 indicates that the code writing rule for a certain bounds access protection structure is that the if condition contains an index and the length of the indexed object. This code structure can be used to determine if the index is less than the length of the indexed object, belonging to the second type of bounds access protection structure. The fifth row of Table 2 indicates that the code writing rule for a certain bounds access protection structure is that the index is compared with the preceding assignment MIN macro definition. This code structure can be used to determine both if the index is greater than 0 and if the index is less than the length of the indexed object, belonging to the third type of bounds access protection structure.

[0090] Table 2 Rules for Protective Structures Across Boundaries

[0091]

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

[0093] In one embodiment, a static scanning method for method index out-of-bounds crashes is also provided. This method 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, strings, and other data types that use methods to set / get index values. The method first collects characteristic methods that cause a crash when the index exceeds the length boundary of the indexed object. Then, it uses the WCClangMatcher static scanning tool to obtain the code structure calling the characteristic method and the out-of-bounds protection structure of the input parameter object `index` (index greater than 0 and less than the length of the indexed object) existing before the characteristic method. If an out-of-bounds protection structure for the index `index` exists before the characteristic method, the characteristic structure is considered to have no out-of-bounds crash risk; otherwise, an out-of-bounds crash risk exists.

[0094] like Figure 5 As shown, users can first upload the static scanning rule project to a Git repository, then configure the pipeline, add plugins for automatic code retrieval and code commit notification for the target project, trigger static scanning based on code commits, and automatically generate a ticket and notify the test executor after the task is completed. The specific implementation process may include the following steps:

[0095] (1) Feature collection methods.

[0096] Based on historical crash issues in the project, we collected the method names that would cause a crash when the index exceeds the length boundary of the indexed object. The characteristic methods collected are shown in Table 1.

[0097] (2) Collect outbound protection code writing method.

[0098] Index out-of-bounds protection requires two conditions to be met simultaneously: 1. The index is greater than 0; 2. The index is less than the length of the indexed object. In actual code writing, there are many ways to write these two conditions, which are summarized in Table 2 after being divided into equivalence classes.

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

[0100] Some indexed variables are made to have the prerequisite of not being negative by means of attribute restrictions when they are declared and assigned. 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 is shown in Table 3.

[0101] Table 3. Schematic diagram of variable attribute classification

[0102]

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

[0104] Since the matching of feature structures and boundary protection structures are independent of each other, when comparing data, the consistency judgment of the index variable in the feature structure and the boundary protection structure must simultaneously meet the following conditions:

[0105] 1. Within the same method implementation;

[0106] 2. The unique IDs of the AST structures corresponding to the index variables are the same;

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

[0108] In this embodiment, the feature structure with a non-negative index attribute can be named feature structure 1, and the other can be named feature structure 2.

[0109] Combining the classification in (2), such as Figure 6 As shown, the rules for determining boundary crossing protection are as follows:

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

[0111] 2. For feature structure 1, when protection condition 2 exists, there is boundary crossing protection;

[0112] 3. For feature structure 2, when both protection condition 1 and protection condition 2 exist, there is boundary crossing protection.

[0113] Finally, by identifying the parts of all feature structures that do not have boundary protection, the problem structure can be obtained.

[0114] This embodiment provides a static scanning method for method index out-of-bounds crashes that does not restrict data types. It uses the code structure calling characteristic methods as the risk structure (characteristic methods can be added according to the actual project situation). Within the same method implementation, it searches for the out-of-bounds protection structure of the input parameter object—the index—of the called characteristic method. 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, is time-efficient, and facilitates checking incremental commits at any time. It can also proactively identify potential problems.

[0115] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0116] Based on the same inventive concept, this application also provides an index out-of-bounds testing apparatus for implementing the index out-of-bounds testing method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more embodiments of the index out-of-bounds testing apparatus provided below can be found in the limitations of the index out-of-bounds testing method described above, and will not be repeated here.

[0117] In one embodiment, such as Figure 7 As shown, an index out-of-bounds testing 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 testing module 704, wherein:

[0118] The first index acquisition module 701 is used to acquire the code to be tested, and to acquire 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 that has the risk of index out of bounds.

[0119] The second index acquisition module 702 is used to acquire at least one out-of-bounds protection structure contained in the code to be tested, and to acquire the second index corresponding to each out-of-bounds protection structure.

[0120] The structure association construction module 703 is used to obtain the association relationship between each target feature structure and each boundary 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 under test based on the association relationship.

[0122] Each module in the aforementioned index out-of-bounds testing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.

[0123] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 8 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores the code data to be tested. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements an index out-of-bounds testing method.

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

[0125] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0126] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.

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

[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, data stored, data displayed, 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 the relevant data must comply with relevant regulations.

[0129] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this 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. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0130] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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 embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A method of index out of bounds testing, the method comprising: The method comprises: acquiring a to-be-tested code, and acquiring 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 out-of-bound risk; the acquiring of the at least one target feature structure contained in the to-be-tested code comprises: acquiring a pre-set target feature structure rule table; the target feature structure rule table stores a target method name corresponding to each target feature structure and a target object type of a calling object calling each feature structure; acquiring a method name of each feature structure contained in the to-be-tested code and an object type of a calling object calling each feature structure; in a case where 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 as the target feature structure; acquiring at least one out-of-bound protection structure contained in the to-be-tested code, and acquiring a second index corresponding to each out-of-bound protection structure; based on each first index and each second index, acquiring an association relationship between each target feature structure and each out-of-bound protection structure; comprising: acquiring 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; in a case where there is a current second index matching the current first index in each second index, acquiring a current out-of-bound protection structure corresponding to the current second index; constructing an association relationship between the current target feature structure and the current out-of-bound protection structure; according to the association relationship, obtaining an index out-of-bound test result of each target feature structure in the to-be-tested code; comprising: in a case where the association relationship contains the association relationship between the current target feature structure and the current out-of-bound protection structure, acquiring an index attribute of the current first index and a structure attribute of the current out-of-bound protection structure; in a case where the structure attribute matches the index attribute, it is determined that the index out-of-bound test result of the current target feature structure is test passed; in a case where the structure attribute does not match the index attribute, it is determined that the index out-of-bound test result of the current target feature structure is test failed.

2. The method of claim 1, wherein, after the acquiring of the current first index and the current target feature structure corresponding to the current first index, further comprising: in a case where any second index satisfies a pre-set matching condition, taking the second index as a current second index matching the current first index; the pre-set matching condition comprises: the out-of-bound 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 before the code line number where the current first index is located.

3. The method of claim 1, wherein, The index attribute comprises a first index attribute and a second index attribute, and the structure attribute comprises a first structure attribute, a second structure attribute, and a third structure attribute; the first index attribute represents that a first index exists a property limit condition greater than 0, and the second index attribute represents that the first index does not exist the property limit condition; The first structure attribute represents that a boundary protection structure is used to determine whether the first index is greater than 0, the second structure attribute represents that the boundary protection structure is used to determine whether the first index is less than the length of an indexed object, and the third structure attribute represents that the 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 the index attribute of the current first index and the structure attribute of the current boundary protection structure are obtained, the method further comprises: In a case where the index attribute is the first index attribute, if the structure attribute of the current boundary protection structure is the second structure attribute or the third structure attribute, it is determined that the structure attribute matches the index attribute; In a case where the index attribute is the second index attribute, if the structure attribute of the current boundary protection structure is the third structure attribute or the structure attribute of the current boundary protection structure comprises the first structure attribute and the second structure attribute, it is determined that the structure attribute matches the index attribute.

4. The method according to claim 1 or 2, characterized in that, After the current first index and the current target feature structure corresponding to the current first index are obtained, the method further comprises: In a case where there is no current second index that matches the current first index in each second index, it is determined that there is no boundary protection structure associated with the current target feature structure in the to-be-tested code; The index out-of-bound test result of each target feature structure in the to-be-tested code is obtained according to the association relationship, comprising: In a case where there is no boundary protection structure associated with the current target feature structure in the to-be-tested code, it is determined that the index out-of-bound test result of the current target feature structure is test failure.

5. The method of claim 1, wherein, The at least one boundary protection structure contained in the to-be-tested code is obtained, comprising: A pre-set boundary protection structure rule table is obtained; the boundary protection structure rule table stores code writing rules of each boundary protection structure; In a case where any sub-code structure in the to-be-tested code satisfies any code writing rule stored in the boundary protection structure rule table, the sub-code structure is determined to be the boundary protection structure contained in the to-be-tested code.

6. An index out of bounds testing apparatus characterized by, The device comprises: The first index obtaining module is configured to obtain a to-be-tested code, and obtain 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 out-of-bound risk; the first index obtaining module is further configured to obtain a pre-set target feature structure rule table; the target feature structure rule table stores a target method name corresponding to each target feature structure and a target object type of a calling object calling each feature structure; the first index obtaining module is further configured to obtain a method name of each feature structure contained in the to-be-tested code and an object type of a calling object calling each feature structure; in a case where 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; The second index obtaining module is configured to obtain at least one out-of-bound protection structure contained in the to-be-tested code, and obtain a second index corresponding to each out-of-bound protection structure; The structure association constructing module is configured to obtain an association relationship between each target feature structure and each out-of-bound protection structure based on each first index and each second index; the structure association constructing module is further configured to obtain 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; in a case where a current second index matching the current first index exists in the second indexes, a current out-of-bound protection structure corresponding to the current second index is obtained; an association relationship between the current target feature structure and the current out-of-bound protection structure is constructed; The index out-of-bound testing module is configured to obtain an index out-of-bound testing result of each target feature structure in the to-be-tested code according to the association relationship; the index out-of-bound testing module is further configured to obtain an index attribute of the current first index and a structure attribute of the current out-of-bound protection structure in a case where the association relationship includes the association relationship between the current target feature structure and the current out-of-bound protection structure; in a case where the structure attribute matches the index attribute, the index out-of-bound testing result of the current target feature structure is determined to be test passed; in a case where the structure attribute does not match the index attribute, the index out-of-bound testing result of the current target feature structure is determined to be test failed.

7. The apparatus of claim 6, wherein, The structure association constructing module is further configured to, in a case where any second index satisfies a pre-set matching condition, take the second index as a current second index matching the current first index; The pre-set matching condition includes that the out-of-bound protection structure corresponding to the second index and the current target feature structure are located in a same function method; The index identifier corresponding to the second index is the same as the index identifier corresponding to the current first index; and a code line number where the second index is located is before a code line number where the current first index is located. 8.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-7. The processor executes the computer program to implement the steps of the method in any one of claims 1 to 6.

9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program, which when executed by a processor, implements the steps of the method of any one of claims 1 to 6.

10. A computer program product comprising a computer program, characterized in that, The computer program, which when executed by a processor, implements the steps of the method of any one of claims 1 to 6.

Citation Information

Patent Citations

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

    CN118796177A

  • Dynamic arrays and overlays with bounds policies

    US20030014607A1