Skip to content

Commit 851a1a8

Browse files
committed
Merge remote-tracking branch 'origin' into dev_1.18.0
2 parents 31fafff + b41b6e3 commit 851a1a8

File tree

6 files changed

+59
-43
lines changed

6 files changed

+59
-43
lines changed

.github/workflows/ci-lingvo.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
sudo apt-get update
5151
sudo apt-get -y -q install ffmpeg libavcodec-extra
5252
python -m pip install --upgrade pip setuptools wheel
53-
pip install -q -r <(sed '/^scipy/d;/^matplotlib/d;/^pandas/d;/^statsmodels/d;/^numba/d;/^jax/d;/^h5py/d;/^Pillow/d;/^pytest/d;/^pytest-mock/d;/^torch/d;/^torchaudio/d;/^torchvision/d;/^xgboost/d;/^requests/d;/^tensorflow/d;/^keras/d;/^kornia/d;/^librosa/d;/^tqdm/d;/^timm/d;/^catboost/d;/^scikit-learn/d' requirements_test.txt)
53+
pip install -q -r <(sed '/^scipy/d;/^matplotlib/d;/^pandas/d;/^statsmodels/d;/^numba/d;/^jax/d;/^h5py/d;/^Pillow/d;/^pytest/d;/^pytest-mock/d;/^torch/d;/^torchaudio/d;/^torchvision/d;/^xgboost/d;/^requests/d;/^tensorflow/d;/^keras/d;/^kornia/d;/^librosa/d;/^tqdm/d;/^timm/d;/^catboost/d;/^scikit-learn/d;/^GPy/d;/^lief/d' requirements_test.txt)
5454
pip install scipy==1.5.4
5555
pip install matplotlib==3.3.4
5656
pip install pandas==1.1.5
@@ -76,6 +76,8 @@ jobs:
7676
pip install tqdm==4.64.1
7777
pip install catboost==1.1.1
7878
pip install scikit-learn==0.24.2
79+
pip install GPy==1.10.0
80+
pip install lief==0.12.3
7981
pip list
8082
- name: Run ${{ matrix.name }} Tests
8183
run: pytest --cov-report=xml --cov=art --cov-append -q -vv tests/estimators/speech_recognition/test_tensorflow_lingvo.py --framework=${{ matrix.framework }} --durations=0

.github/workflows/ci-pytorch.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ jobs:
3434
torch: 1.13.1+cpu
3535
torchvision: 0.14.1+cpu
3636
torchaudio: 0.13.1
37-
- name: PyTorch 2.1.2 (Python 3.10)
37+
- name: PyTorch 2.2.1 (Python 3.10)
3838
framework: pytorch
3939
python: '3.10'
40-
torch: 2.1.2
41-
torchvision: 0.16.2+cpu
42-
torchaudio: 2.1.2
40+
torch: 2.2.1
41+
torchvision: 0.17.1+cpu
42+
torchaudio: 2.2.1
4343

4444
name: ${{ matrix.name }}
4545
steps:

.github/workflows/ci-tensorflow-v1.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
sudo apt-get update
4949
sudo apt-get -y -q install ffmpeg libavcodec-extra
5050
python -m pip install --upgrade pip setuptools wheel
51-
pip install -q -r <(sed '/^pandas/d;/^scipy/d;/^matplotlib/d;/^xgboost/d;/^tensorflow/d;/^keras/d;/^jax/d;/^torch/d;/^Pillow/d;/^h5py/d;/^scikit-learn/d' requirements_test.txt)
51+
pip install -q -r <(sed '/^pandas/d;/^scipy/d;/^matplotlib/d;/^xgboost/d;/^tensorflow/d;/^keras/d;/^jax/d;/^torch/d;/^Pillow/d;/^h5py/d;/^kornia/d;/^scikit-learn/d;/^pytest-mock/d;/^GPy/d;/^lief/d;/^statsmodels/d' requirements_test.txt)
5252
pip install pandas==1.3.5
5353
pip install scipy==1.7.2
5454
pip install matplotlib==3.5.3
@@ -62,7 +62,12 @@ jobs:
6262
pip install torchvision==0.14.1+cpu
6363
pip install Pillow==9.5.0
6464
pip install h5py==3.8.0
65+
pip install kornia==0.6.12
6566
pip install scikit-learn==1.0.2
67+
pip install pytest-mock~=3.11.1
68+
pip install GPy~=1.10.0
69+
pip install lief==0.12.3
70+
pip install statsmodels==0.13.5
6671
pip list
6772
- name: Run Tests
6873
run: ./run_tests.sh ${{ matrix.framework }}

.github/workflows/dockerhub.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ jobs:
2424
uses: actions/checkout@v3
2525

2626
- name: Log in to Docker Hub
27-
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
27+
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
2828
with:
2929
username: ${{ secrets.DOCKER_HUB_USERNAME }}
3030
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
3131

3232
- name: Extract metadata (tags, labels) for Docker
3333
id: meta
34-
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
34+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
3535
with:
3636
images: adversarialrobustnesstoolbox/releases
3737
tags: |
3838
type=raw,value={{branch}}-1.17.1-{{sha}}
3939
type=semver,pattern={{version}}
4040
4141
- name: Build and push Docker image
42-
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
42+
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
4343
with:
4444
context: .
4545
push: true

art/attacks/evasion/pe_malware_attack.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def __init__(
8383
'input_dim': the number of discrete values, normally 257.
8484
'embedding_size': size of the embedding layer. Default 8.
8585
:param num_of_iterations: The number of iterations to apply.
86-
:param l_0: l_0 bound for the attack. If less then 1 it is interpreted as a fraction of the file size.
86+
:param l_0: l_0 bound for the attack. If less than 1 it is interpreted as a fraction of the file size.
8787
If larger than 1 it is interpreted as the total number of permissible features to change.
8888
:param l_r: Learning rate for the optimisation
89-
:param use_sign: If we want to use the sign of the gradient, rather then the gradient itself.
89+
:param use_sign: If we want to use the sign of the gradient, rather than the gradient itself.
9090
:param verbose: Show progress bars.
9191
"""
9292
super().__init__(estimator=classifier)
@@ -333,7 +333,7 @@ def pull_out_adversarial_malware(
333333
334334
:param x: Batch of data which will contain a mix of adversarial examples and unperturbed data.
335335
:param y: Labels indicating which are valid adversarial examples or not.
336-
:param initial_dtype: Data can be given in a few formats (uin16, float, etc) so use initial_dtype
336+
:param initial_dtype: Data can be given in a few formats (uin16, float, etc.) so use initial_dtype
337337
to make the returned sample match the original.
338338
:param sample_sizes: Size of the original data files
339339
:param input_perturb_sizes: List of length batch size, each element is in itself a list containing
@@ -346,7 +346,7 @@ def pull_out_adversarial_malware(
346346
"""
347347
num_of_malware_samples = int(np.sum(y))
348348

349-
# make array and allocate, much faster then appending to list and converting
349+
# make array and allocate, much faster than appending to list and converting
350350
adv_x = np.zeros((num_of_malware_samples, x.shape[1]), dtype=initial_dtype)
351351
adv_y = np.ones((num_of_malware_samples, 1))
352352

@@ -475,7 +475,7 @@ def generate( # pylint: disable=W0221
475475
) -> np.ndarray:
476476
"""
477477
Generates the adversarial examples. x needs to be composed of valid files by default which can support the
478-
adversarial perturbation and so are malicious and can support the assigned L0 budget. They can obtained by
478+
adversarial perturbation and so are malicious and can support the assigned L0 budget. They can be obtained by
479479
using `pull_out_valid_samples` on the data.
480480
481481
This check on the input data can be over-ridden by toggling the flag verify_input_data
@@ -488,7 +488,7 @@ def generate( # pylint: disable=W0221
488488
After all the regions marked in perturb_sizes and perturb_starts have been assigned and automatically_append is
489489
set to true and remaining l0 perturbation the extra perturbation is added at the end in an append style attack.
490490
491-
:param x: A array with input data.
491+
:param x: An array with input data.
492492
:param y: (N, 1) binary labels to make sure the benign files are zero masked.
493493
:param sample_sizes: The size of the original file, before it was padded to the input size required by MalConv
494494
:param automatically_append: Whether to automatically append extra spare perturbation at the end of the file.
@@ -564,7 +564,7 @@ def generate( # pylint: disable=W0221
564564
for _ in trange(self.num_of_iterations, desc="PE Adv. Malware", disable=not self.verbose):
565565
gradients = self.estimator.class_gradient(embeddings, label=0)
566566
# go from (bsize x 1 x features x embedding size) -> (bsize x features x embedding size) in a
567-
# framework agnostic manner.
567+
# framework-agnostic manner.
568568
gradients = gradients[:, 0, :, :]
569569
gradients = -1 * gradients
570570
embeddings = self.update_embeddings(embeddings, gradients, mask)
@@ -590,7 +590,7 @@ def process_file(
590590
Go from raw file to numpy array.
591591
592592
:param filepath: Path to the file we convert to a numpy array
593-
:param padding_char: The char to use to pad the input if it is shorter then maxlen
593+
:param padding_char: The char to use to pad the input if it is shorter than maxlen
594594
:param maxlen: Maximum size of the file processed by the model. Currently set to 1MB
595595
:return data: A numpy array of the PE file
596596
:return size_of_original_file: Size of the PE file
@@ -626,17 +626,22 @@ def get_peinfo(
626626

627627
cleaned_dump = {}
628628

629-
binary = lief.parse(filepath) # pylint: disable=I1101
629+
binary_load = lief.parse(filepath) # pylint: disable=I1101
630+
if binary_load is not None:
631+
binary = binary_load
632+
else:
633+
raise ValueError("Failed to load binary.")
634+
630635
for section in binary.sections:
631636
section_info = {}
632-
slack = section.sizeof_raw_data - section.virtual_size
633-
section_info["PointerToRawData"] = section.pointerto_raw_data
634-
section_info["VirtualAddress"] = section.virtual_size
635-
section_info["SizeOfRawData"] = section.sizeof_raw_data
637+
slack = section.sizeof_raw_data - section.virtual_size # type: ignore
638+
section_info["PointerToRawData"] = section.pointerto_raw_data # type: ignore
639+
section_info["VirtualAddress"] = section.virtual_size # type: ignore
640+
section_info["SizeOfRawData"] = section.sizeof_raw_data # type: ignore
636641
cleaned_dump[section.name] = section_info
637642
if slack > 0:
638643
size_of_slack.append(slack)
639-
start_of_slack.append(section.pointerto_raw_data + section.virtual_size)
644+
start_of_slack.append(section.pointerto_raw_data + section.virtual_size) # type: ignore
640645

641646
if save_to_json_path is not None:
642647
with open(save_to_json_path, "w", encoding="utf8") as outfile:
@@ -675,7 +680,7 @@ def insert_section(
675680
:param bytes_to_assign: (Optional) how many bytes we wish to specify when inserting a new section.
676681
If unspecified the whole l0 budget will be used on a single section.
677682
:param verbose: lief outputs a lot to the console, particularly if we are processing many files.
678-
By default suppress printing of messages. Can be toggled on/off by True/False
683+
By default, suppress printing of messages. Can be toggled on/off by True/False
679684
:return manipulated_data: Executable with section inserted and turned into a numpy array of
680685
the appropriate size
681686
:return len(manipulated_file): Size of original file
@@ -690,7 +695,11 @@ def insert_section(
690695
if not verbose:
691696
lief.logging.disable()
692697

693-
binary = lief.PE.parse(datapoint)
698+
binary_parse = lief.PE.parse(datapoint)
699+
if binary_parse is not None:
700+
binary = binary_parse
701+
else:
702+
raise ValueError("Failed to load binary.")
694703

695704
name_in_use = True
696705
while name_in_use:
@@ -705,8 +714,8 @@ def insert_section(
705714
new_section = lief.PE.Section(new_section_name)
706715

707716
if bytes_to_assign is None:
708-
if self.l_0 < 1: # l0 is a fraction of the filesize
709-
# if its a filepath we need to get the file size
717+
if self.l_0 < 1: # l0 is a fraction of the file size
718+
# if it's a filepath we need to get the file size
710719
if isinstance(datapoint, str):
711720
with open(datapoint, "rb") as file:
712721
open_file = file.read()
@@ -721,9 +730,9 @@ def insert_section(
721730
perturbation_size = int(sample_size * self.l_0)
722731
else: # or l0 is interpreted as total perturbation size
723732
perturbation_size = int(self.l_0)
724-
new_section.content = [random.randint(0, 255) for _ in range(perturbation_size)]
733+
new_section.content = [random.randint(0, 255) for _ in range(perturbation_size)] # type: ignore
725734
else:
726-
new_section.content = [random.randint(0, 255) for _ in range(bytes_to_assign)]
735+
new_section.content = [random.randint(0, 255) for _ in range(bytes_to_assign)] # type: ignore
727736

728737
# we add the new section at the end of the existing sections
729738
section_end_points = []
@@ -766,7 +775,7 @@ def insert_section(
766775

767776
manipulated_data = np.ones((maxlen,), dtype=np.uint16) * padding_char
768777

769-
# Only process files which are less then the max file size supported
778+
# Only process files which are less than the max file size supported
770779
if len(manipulated_file) < maxlen:
771780
manipulated_data[: len(manipulated_file)] = manipulated_file[:maxlen]
772781

requirements_test.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
numpy>=1.18.5,<1.27
44
scipy==1.10.1
55
matplotlib==3.7.1
6-
scikit-learn==1.4.0
6+
scikit-learn==1.4.1.post1
77
six==1.16.0
88
Pillow==10.2.0
99
tqdm==4.66.1
10-
statsmodels==0.13.5
10+
statsmodels==0.14.1
1111
pydub==0.25.1
1212
resampy==0.4.2
1313
ffmpeg-python==0.2.0
1414
cma==3.3.0
15-
pandas==2.1.4
15+
pandas==2.2.1
1616
librosa==0.10.1
1717
numba~=0.56.4
1818
opencv-python
@@ -31,21 +31,21 @@ mxnet-native==1.8.0.post0
3131

3232
# PyTorch
3333
--find-links https://download.pytorch.org/whl/cpu/torch_stable.html
34-
torch==2.1.2
35-
torchaudio==2.1.2
36-
torchvision==0.16.2+cpu
34+
torch==2.2.1
35+
torchaudio==2.2.1
36+
torchvision==0.17.1+cpu
3737

3838
# PyTorch image transformers
3939
timm==0.9.2
4040

41-
catboost==1.2.2
42-
GPy==1.10.0
43-
lightgbm==4.1.0
44-
xgboost==2.0.2
41+
catboost==1.2.3
42+
GPy==1.13.1
43+
lightgbm==4.3.0
44+
xgboost==2.0.3
4545

46-
kornia~=0.6.12
46+
kornia~=0.7.1
4747
tensorboardX==2.6.2.2
48-
lief==0.12.3
48+
lief==0.14.1
4949
jax[cpu]==0.4.23
5050

5151
# Lingvo ASR dependencies
@@ -58,7 +58,7 @@ jax[cpu]==0.4.23
5858
pytest~=7.4.3
5959
pytest-flake8~=1.1.1
6060
flake8~=4.0.1
61-
pytest-mock~=3.10.0
61+
pytest-mock~=3.12.0
6262
pytest-cov~=4.1.0
6363
requests~=2.31.0
6464

0 commit comments

Comments
 (0)