def test_slack_attacks(art_warning, fix_get_synthetic_data, fix_make_dummy_model):
    """
    Testing modification of certain regions in the PE file
    """
    try:
        # Third check: Slack insertion attacks.

        def generate_synthetic_slack_regions(size):
            """
            Generate 4 slack regions per sample, each of size 250.
            """

            batch_of_slack_starts = []
            batch_of_slack_sizes = []

            for _ in range(5):
                size_of_slack = []
                start_of_slack = []
                start = 0
                for _ in range(4):
                    start += 1000
                    start_of_slack.append(start)
                    size_of_slack.append(size)
                batch_of_slack_starts.append(start_of_slack)
                batch_of_slack_sizes.append(size_of_slack)
            return batch_of_slack_starts, batch_of_slack_sizes

        param_dic = {"maxlen": 2**20, "input_dim": 257, "embedding_size": 8}
        # First check: with no perturbation the malware of sufficient size, and benign files, should be unperturbed
        attack = MalwareGDTensorFlow(
            classifier=fix_make_dummy_model[0], embedding_weights=fix_make_dummy_model[1], l_0=0, param_dic=param_dic
        )

        l0_budget = 1250
        attack.l_0 = l0_budget
        x = np.copy(fix_get_synthetic_data[0])
        y = np.copy(fix_get_synthetic_data[1])
        size_of_files = np.copy(fix_get_synthetic_data[2])

        batch_of_section_starts, batch_of_section_sizes = generate_synthetic_slack_regions(size=250)
        adv_x, adv_y, adv_sizes, batch_of_section_starts, batch_of_section_sizes = attack.pull_out_valid_samples(
            x,
            y,
            sample_sizes=size_of_files,
            perturb_starts=batch_of_section_starts,
            perturb_sizes=batch_of_section_sizes,
        )

        # We should only have 2 files as the following cannot be converted to valid adv samples:
        #   2nd datapoint (file too large to support any modifications)
        #   4th datapoint (attack requires appending 250 bytes to end of file which this datapoint cannot support)
        #   5th datapoint (benign file)
        assert len(adv_x) == 2

        adv_x = attack.generate(
            adv_x, adv_y, adv_sizes, perturb_sizes=batch_of_section_sizes, perturb_starts=batch_of_section_starts
        )

        j = 0
        for i, size in enumerate(fix_get_synthetic_data[2]):
            if i in [0, 2]:
                slack_starts = batch_of_section_starts[j]
                slack_sizes = batch_of_section_sizes[j]
                beginning_pos = 0
                total_perturbation = 0
                for slack_start, slack_size in zip(slack_starts, slack_sizes):
                    assert np.array_equal(
                        adv_x[j, beginning_pos:slack_start], fix_get_synthetic_data[0][i, beginning_pos:slack_start]
                    )

                    assert not np.array_equal(
                        adv_x[j, slack_start : slack_start + slack_size],
                        fix_get_synthetic_data[0][i, slack_start : slack_start + slack_size],
                    )
                    beginning_pos = slack_start + slack_size
                    total_perturbation += slack_size

                # from the last slack region to end of file
                assert np.array_equal(adv_x[j, beginning_pos:size], fix_get_synthetic_data[0][i, beginning_pos:size])
                remaining_perturbation = l0_budget - total_perturbation
                assert remaining_perturbation == 250

                # append portion of the attack has been conducted
                assert not np.array_equal(
                    adv_x[j, size : size + remaining_perturbation],
                    fix_get_synthetic_data[0][i, size : size + remaining_perturbation],
                )

                # from end of append to end of datapoint
                assert np.array_equal(
                    adv_x[j, size + remaining_perturbation :],
                    fix_get_synthetic_data[0][i, size + remaining_perturbation :],
                )

                j += 1
            else:
                assert np.array_equal(x[i], fix_get_synthetic_data[0][i])
    except ARTTestException as e:
        art_warning(e)

    Testing modification of certain regions in the PE file
    
tests/attacks/evasion/test_pe_malware_attack.py