# US 2022/0292200 A1 · Deep-learning based device and method for detecting source-code vulnerability with improved robustness

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2022/0292200 A1
- Document ID: US20220292200A1
- Status: Published application
- Kind: A1
- Application number: 17/444,612
- Filed: 2021-08-06
- Published: 2022-09-15
- Earliest claimed: 2021-03-10
- Assignees: Huazhong University of Science and Technology
- Applicants: Huazhong University of Science and Technology
- Inventors: Deqing Zou; Jing Tang; Zhen Li; Hai Jin
- Web page: https://patentgrep.com/patent/US20220292200A1

## CPC

- G06F 21/577: {Assessing vulnerabilities and evaluating computer system security}
- G06F 18/214: Generating training patterns; Bootstrap methods, e.g. bagging or boosting
- G06F 21/54: by adding security routines or objects to programs
- G06F 21/554: {involving event detection and direct action}
- G06F 21/563: {by source code analysis}
- G06N 3/044: Recurrent networks, e.g. Hopfield networks
- G06N 3/0442: characterised by memory or gating, e.g. long short-term memory [LSTM] or gated recurrent units [GRU]
- G06N 3/0464: Convolutional networks [CNN, ConvNet]
- G06N 3/08: Learning methods
- G06N 3/09: Supervised learning
- G06N 3/094: Adversarial learning
- G06F 2221/033: Test or assess software
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

The present invention relates a device for improving robustness of deep-learning based detection of source-code vulnerability, the device at least comprises a code-converting module, a mapping module, and a neural-network module, wherein the mapping module is in data connection with the code-converting module, the mapping module is in data connection with the neural-network module, respectively, and the neural-network module includes at least two first classifiers, based on a received first training program source code, the mapping module maps a plurality of code snippets, and the neural-network module trains the at least two first classifiers according to a first sample vector. The present invention improves the robustness of detection of source-code vulnerability by performing classification training on the feature generators and the classifiers.

## Claims

### Claim 1

A device for improving robustness of deep-learning based detection of source-code vulnerability, the device at least comprises a code-converting module, a mapping module, and a neural-network module, wherein the mapping module is in data connection with the code-converting module, the mapping module is in data connection with the neural-network module, respectively, and the neural-network module includes at least two first classifiers,
based on a received first training program source code, the code-converting module generates a second training program source code with assailability by means of code converting,
the mapping module maps a plurality of code snippets formed by separating the second training program source code to a second sample vector, and
the neural-network module trains the at least two first classifiers according to a first sample vector corresponding to the first training program source code and a second sample vector corresponding to the second training program source code, respectively, until trained data reach a training threshold.

### Claim 2 (depends on 1)

The device of claim 1, wherein the neural-network module training feature generators and/or the classifiers based on a recurrent neural network model at least comprises:
training at least one first feature generator and at least two said first classifiers based on the first sample vector corresponding to the first training program source code until a prediction difference between the at least two first classifiers is minimized;
training at least two second classifiers based on the second sample vector corresponding to the second training program source code until a prediction difference between the at least two second classifiers is maximized;
training the first feature generator that has been trained to have the minimized prediction difference into a second feature generator based on the second sample vector corresponding to the second training program source code and at least two said second classifiers that have been trained to have the maximized prediction difference.

### Claim 3 (depends on 2)

The device of claim 2, wherein the neural-network module training feature generators and/or the classifiers based on a recurrent neural network model further comprises:
training the second classifier and the first feature generator by means of iterative training.

### Claim 4 (depends on 3)

The device of claim 3, wherein
training the at least two second classifiers based on the second sample vector corresponding to the second training program source code comprises:
calculating a first loss happening when the second classifiers classify the first sample vector, calculating a second loss happening when the second classifiers classify a hard sample in the second sample vector, and
determining a prediction difference of the recurrent neural network model based on a difference between the first loss and the second loss.

### Claim 5 (depends on 4)

The device of claim 4, wherein the first loss is calculated using an equation of:
L
c
(
X
)
=
-
∑
l
=
1
2
{
E
x
s
∼
X
[
y
s
·
log
⁡
(
c
l
*
(
x
s
,
F
)
)
+
(
1
-
y
s
)
·
log
⁡
(
1
-
c
l
*
(
x
s
,
F
)
)
]
}
where xs denotes a vector, ys denotes a sample label, cl*(xs,F) denotes a prediction probability of the second classifier on a vulnerability sample.

### Claim 6 (depends on 4)

The device of claim 4, wherein the second loss is calculated using an equation of:
Lh(X″)=Exd″˜X″[|c1*(xd″,F)−c2*(xd″,F)|]
where c1*(xd″,F) denotes prediction probability of one of the second classifiers on a hard sample, and c2*(xd″,F) denotes prediction probability of the other of the second classifiers on the hard sample.

### Claim 7 (depends on 4)

The device of claim 4, wherein determining the prediction difference of the recurrent neural network model based on the difference between the first loss and the second loss is achieved by calculating:
min
C
1
*
⁢
C
2
*
[
L
c
(
X
)
-
L
h
(
X
″
)
]
where Lc(X) denotes the first loss, and Lh(X″) denotes the second loss of the hard sample.

### Claim 8 (depends on 1)

The device of claim 1, wherein the code-converting module is configured to input a source code of the first training set program and at least one code shifting method, so as to generate at least one type of code shifting programs.

### Claim 9 (depends on 1)

The device of claim 1, wherein the mapping module is configured to generate each training program source code as code snippets with different levels of granularity.

### Claim 10

A device for detecting source-code vulnerability, at least comprising a mapping module and a neural-network module, wherein the mapping module and the neural-network module are in data connection, and the neural-network module includes at least two second classifiers,
the mapping module maps a plurality of code snippets formed by separating a target program source code to a first sample vector,
the neural-network module performs vulnerability detection based on the first sample vector corresponding to the first target program source code,
where a prediction probability for a vulnerability sample is smaller than a threshold, determining that the target program source code is a vulnerability-free sample;
where the prediction probability for the vulnerability sample is not smaller than the threshold, determining that the target program source code is a vulnerability sample, and wherein the second classifier is trained through:
the mapping module separating a second training program source code generated by the code-converting module based on a first training program source code by means of code converting into a plurality of code snippets, and mapping the plurality of code snippets to a second sample vector, and
the neural-network module training the at least two first classifiers according to a first sample vector corresponding to the first training program source code and a second sample vector corresponding to the second training program source code, respectively, until trained data reach a training threshold.

### Claim 11

A method for improving robustness of deep-learning based detection of source-code vulnerability, the device at least comprises a code-converting module, a mapping module, and a neural-network module, wherein the mapping module is in data connection with the code-converting module, the mapping module is in data connection with the neural-network module, respectively, and the neural-network module includes at least two first classifiers,
based on a received first training program source code, the code-converting module generates a second training program source code with assailability by means of code converting,
the mapping module maps a plurality of code snippets formed by separating the second training program source code to a second sample vector, and
the neural-network module trains the at least two first classifiers according to a first sample vector corresponding to the first training program source code and a second sample vector corresponding to the second training program source code, respectively, until trained data reach a training threshold.

### Claim 12 (depends on 11)

The method of claim 11, wherein the neural-network module training feature generators and/or the classifiers based on a recurrent neural network model at least comprises:
training at least one first feature generator and at least two said first classifiers based on the first sample vector corresponding to the first training program source code until a prediction difference between the at least two first classifiers is minimized;
training at least two second classifiers based on the second sample vector corresponding to the second training program source code until a prediction difference between the at least two second classifiers is maximized;
training the first feature generator that has been trained to have the minimized prediction difference into a second feature generator based on the second sample vector corresponding to the second training program source code and at least two said second classifiers that have been trained to have the maximized prediction difference.

### Claim 13 (depends on 12)

The method of claim 12, wherein the neural-network module training feature generators and/or the classifiers based on a recurrent neural network model further comprises:
training the second classifier and the first feature generator by means of iterative training.

### Claim 14 (depends on 13)

The method of claim 13, wherein
training the at least two second classifiers based on the second sample vector corresponding to the second training program source code comprises:
calculating a first loss happening when the second classifiers classify the first sample vector,
calculating a second loss happening when the second classifiers classify a hard sample in the second sample vector, and
determining a prediction difference of the recurrent neural network model based on a difference between the first loss and the second loss.

### Claim 15 (depends on 14)

The method of claim 14, wherein the first loss is calculated using an equation of:
L
c
(
X
)
=
-
∑
l
=
1
2
{
E
x
s
∼
X
[
y
s
·
log
⁡
(
c
l
*
(
x
s
,
F
)
)
+
(
1
-
y
s
)
·
log
⁡
(
1
-
c
l
*
(
x
s
,
F
)
)
]
}
where xs denotes a vector, ys denotes a sample label, cl*(xs,F) denotes a prediction probability of the second classifier on a vulnerability sample.

### Claim 16 (depends on 14)

The method of claim 14, wherein the second loss is calculated using an equation of:
Lh(X″)=Exd″˜X″[|c1*(xd″,F)−c2*(xd″,F)|]
where c1*(xd″,F) denotes prediction probability of one of the second classifiers on a hard sample, and c2*(xd″,F) denotes prediction probability of the other of the second classifiers on the hard sample.

### Claim 17 (depends on 14)

The method of claim 14, wherein determining the prediction difference of the recurrent neural network model based on the difference between the first loss and the second loss is achieved by calculating:
min
C
1
*
⁢
C
2
*
[
L
c
(
X
)
-
L
h
(
X
″
)
]
where Lc(X) denotes the first loss, and Lh(X″) denotes the second loss of the hard sample.

### Claim 18 (depends on 11)

The method of claim 11, wherein the code-converting module is configured to input a source code of the first training set program and at least one code shifting method, so as to generate at least one type of code shifting programs.

### Claim 19 (depends on 11)

The method of claim 11, wherein the mapping module is configured to generate each training program source code as code snippets with different levels of granularity.

### Claim 20

A method for detecting source-code vulnerability, at least involving a mapping module and a neural-network module, wherein the mapping module and the neural-network module are in data connection, and the neural-network module includes at least two second classifiers,
the mapping module maps a plurality of code snippets formed by separating a target program source code to a first sample vector,
the neural-network module performs vulnerability detection based on the first sample vector corresponding to the first target program source code,
where a prediction probability for a vulnerability sample is smaller than a threshold, determining that the target program source code is a vulnerability-free sample;
where the prediction probability for the vulnerability sample is not smaller than the threshold, determining that the target program source code is a vulnerability sample, and
wherein the second classifier is trained through:
the mapping module separating a second training program source code generated by the code-converting module based on a first training program source code by means of code converting into a plurality of code snippets, and mapping the plurality of code snippets to a second sample vector, and
the neural-network module training the at least two first classifiers according to a first sample vector corresponding to the first training program source code and a second sample vector corresponding to the second training program source code, respectively, until trained data reach a training threshold.
