{'fraction_non_alphanumeric': 0.01948270070540813, 'fraction_numerical': 0.012764528048370843, 'mean_word_length': 4.756687077022237, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Downscaling Attack and Defense: Turning What You See Back Into What You Get

The resizing of images, which is typically a required part of preprocessing for computer vision systems, is vulnerable to attack. Images can be created such that the image is completely different at machine-vision scales than at other scales and the default settings for some common computer vision and machine learning systems are vulnerable. We show that defenses exist and are trivial to administer provided that defenders are aware of the threat. These attacks and defenses help to establish the role of input sanitization in machine learning.


Introduction
Computer vision systems typically need to resize their inputs, and those resizing algorithms typically select only a small number of specific pixels from the original image. Those pixels can be specifically modified to contain the elements of a separate image that is completely different from the one that appears at other scales. This attack was first discovered in 2017 by Xiao et al. but without demonstrating defenses. [1] The premise is shown in Figure 1, where a high resolution sloth picture was manipulated so that it resizes to a shark at the 299x299 pixels shape used for the famous InceptionV3 classifier. The resizing algorithm used the default settings in TensorFlow: tf.image.resize(sloth,(299,299)).
Humans typically prefer to view images at a higher resolution than computer vision algorithms do, but also often at lower resolutions than what is provided by even commodity cameras. Using attacks like these, humans reviewing images at full or intermediate scales can be made to see benign images while the machine sees malicious inputs, or alternatively, humans may see restricted content that the machine marks as benign. For example, dissidents could use this technique to share or post images that appear contentious at human-scales but that automated censors view as completely benign. [2,3] The outcome and applicability of these attacks is similar to that of adversarial examples but they are induced in a completely different way. [4][5][6] Blending of images has been used in the design of triggers or backdoors [7,8] but those are unrelated to the present work. The images in downscaling attacks are combined in a different way that allows the images to be completely or nearly completely decoupled from each other. The threat model is also quite different. In the present attack, the attacker does not influence the training process to create a backdoor, they simply arrange the input so that different images are seen by the machine than by the human at another scale.
A useful way to think of these attacks is as artifacts of the rescaling step. Typically the goal of image processing is to minimize artifact generation, but here we are structuring the input image so as to maximize artifacts. Specifically, a second image is steganographically hidden so that it is revealed when rescaled to a specific size and shape. There are long histories in both steganography [9,10] and image processing. [11] This technique would not be prominent in either discipline. It is very ill-suited for steganography because the embedded information is much easier to detect and decode arXiv:2010.02456v2 [cs.CR] 7 Oct 2020 ESTIMATING THE BRITTLENESS OF AI -OCTOBER 9, 2020 than many alternative steganographic methods. And image processing is almost exclusively directed at removing or reducing artifacts rather than increasing them. This paper starts by introducing bilinear interpolation, which is a common default resizing algorithm though not the only vulnerable one. [12] We then describe the process of generating the attacks and defending against them. Then we discuss their implications for machine learning security.

Bilinear Interpolation
A common default resizing method in image processing and machine learning libraries is bilinear interpolation. In it, each pixel in the resized image contains information from only four pixels in the source image. Those four pixels are the four diagonal neighbors in the source image that are closest to where the center of the corresponding pixel in the resized image would be if it was placed in the source image. The intensities of the four source image pixels are combined in two steps, first a weighted average in either the x or y directions, then a weighted average in the remaining direction. The locations of the four source image pixels are illustrated in Figure 2.
Mathematically, let the source image have pixel locations (n − 0.5, m − 0.5) for n and m ranging from (1, 1) to (N, M ) and pixel intensities f n,m which may be vector-valued for color. And let the rescaled image have pixel locations  (i − 0.5, j − 0.5) ranging from (1, 1) to (I, J) with pixel intensities g i,j . Then the continuous-valued location of the rescaled image pixel (i, j) corresponds to the following location in the source image: This continuous-valued location in the source image is then used to find the discrete locations of the four neighboring diagonal pixels with coordinates that are lower (l) and upper (u) with respect to the continuous-valued location.
The resulting pixel intensity in the rescaled image is then calculated according to the following equation that interpolates the pixel values in both the x and y directions.
The weighting in equation 3 may be important in more subtle attacks, but it does not play a role in any of the attacks discussed in this paper because we set all of the four diagonal pixel intensities to the same value. We simply put the full intensity of the desired rescaled pixel value in all four of the corresponding source image pixels.

Generating Downscaling Attacks
The process for generating downscaling attacks is simple. There is a big image like the sloth in the example we have adopted, there is a small image like the shark, and there is a combined image that has elements of the small image scattered throughout the big image. Creating the combined image is simply a matter of copying the right pixels of the small image to the right locations of the big image. The process is provided in pseudocode in Algorithm 1 using the same variable definitions as in Section 2.
If there is a large difference in size between the small and big images then the altered pixels make up a small fraction of the combined image so that the effect can be minimal and difficult for humans to observe at full scale. As the difference in sizes grows, it also becomes increasingly rare for pieces of the smaller image to find their way into rescaled images at intermediate scales.
As an illustration, the combined sloth-shark image (originally 3744x6660) was rescaled to various sizes as shown in Figure 4. At smaller scales, a substantial number of shark pixels are included in the downsampling and might or might not alert a human or secondary computer vision algorithm. At scales just one pixel above and below 299x299, the same is true but the alerting pixels are confined to the corners. At intermediate scales, larger than 299x299, the differences are even less perceptible and elements of the shark may not exist at all. It is also possible to embed a third image that is revealed at a third scale. Figure 5 shows the boat from the movie Jaws placed within the combined sloth-shark picture so that only the boat is seen at the 224x224, which is a common scale for other common image classifiers like VGG16. In generating the full-scale combined image, a few of the boat pixels land in the same spots as the shark pixels so overwrote them. That leads to some boat components in the belly of the shark that are visible on close inspection. Nonetheless, it is still clearly a sloth at large scale, a shark at Inception scale, and a boat at VGG scale, indicating that it is possible to create a single image that is viewed differently by humans and several different image classifiers.

Defending Against Downscaling Attacks
Downscaling attacks are concerning because default settings in several cases are vulnerable, because they are very easy to generate, and because they are almost certain to be effective for any classifier that uses a vulnerable rescaling algorithm. But not all rescaling algorithms are vulnerable and it is fortunately a trivial matter both to detect these attacks and to harden rescaling algorithms.
When viewed at full-scale, these attacks include a regular repeating pattern, the frequency of which depends precisely on the size of the input image and of the rescaled image. So although the perturbations may be not be obvious, a human who knows to look for them can zoom in on the full-scale image and find the pattern. For more automated detection, the patterns become obvious if the image is transformed to the frequency domain as illustrated in Figure 6.   Detecting attacks may be less important than simply defanging them though, and defanging is even more straightforward. The attacks are possible because resizing algorithms only sample a few pixels from the source image for every pixel in the resized image. As described earlier, this sampling procedure can lead to artifacts in non-malicious cases as well, so techniques have already been developed to reduce the impact. One technique is to resize an image over a series of steps rather than all at once. This is the default approach used by the Python Pillow image processing library.
Another, perhaps more secure approach, samples a larger number of pixels in a one-step resizing in a form of antialiasing. [13] Figure 7 shows the principle of antialiasing for scaling a 100x100 image to one that is only 5x5. The figure was generated by observing the intensity of the (2,2) pixel of the 5x5 image after rescaling from the 100x100 image with only one pixel turned on at a time. The idea is to see how much each pixel in the 100x100 image contributes to the (2,2) pixel in the 5x5 version. With antialias turned off, only four locations in the 100x100 image contribute, each contributing a quarter of its intensity. With antialias on, a much wider range of nearby pixels each contribute a much smaller fraction of their intensity. For a downscaling attack to succeed with antialiasing on would require extensive perturbations to the source image.
The practical effectiveness of antialiasing can be seen clearly in Figure 8, where the TensorFlow default settings are used to generate a sloth at intermediate scales and a shark at the machine scale. When resized to the same machine scale with antialiasing on, the resulting image is once again a sloth. The antialiased sloth is slightly blurry, which is a standard artifact caused by antialiasing, but it is certainly not a shark to a human observer.
To gain a sense for the effectiveness of the attack and defenses, we collected 1000 random images from ImageNet [14] and tested two classifiers: InceptionV3 [15] and VGG16. [16] Inception used inputs scaled to 299x299 and VGG used 224x224. The inputs were scaled using the TensorFlow.image.resize() method, using both the default settings and again with antialiasing enabled. VGG requires additional preprocessing steps after rescaling for which we used the Keras preprocess_input method with default settings. For combining the images, we selected randomly from the thousand images such that all thousand are included once as the big image and all thousand are included once as the small image with no repeats and none of the big images has itself as the small image. The combination process was conducted by  Table 1: The attacks are nearly perfectly effective against the Inception classifier they were designed for and almost perfectly ineffective in the presence of antialiasing. For VGG, which uses a different scale for its inputs, the attacks almost never succeed at selecting the embedded image but performance at identifying the bigger image is degraded.
resizing one randomly selected image to 2000x2000 (big image) and another other to 299x299 (small image) then combining them using Algorithm 1.
Each input to the classifier has two images so also has two sets of labels to evaluate, one for the big images and one for the small images. Before evaluating the combined images however, we establish a baseline using clean images that do not have small images embedded in them. Across the top row of Table 1, the top-1 and top-5 accuracies match the reported accuracies for both Inception and VGG. The second row is also as expected: none of the small images were embedded, so the small labels should only be correct at about the one in a thousand and five in a thousand odds of random chance for top-1 and top-5 respectively.
The attacked images show a complete reversal. Inception, which uses the 299x299 scale that the attacks were designed for, sees the big images at only random chance and the embedded images at the full expected accuracy of Inception. VGG, operating at 224x224, on the other hand only sees the embedded images at random chance so is not susceptible to the same attack. It does have a significant drop in performance in observing the big images though. The VGG performance can be understood by revisiting Figure 4 which showed the sloth example at many different scales. The shark was only clear at exactly the 299x299 scales so it is not surprising that the 224x224 scale of VGG results in only random chance for the small image labels. Degraded performance for the big image labels is also unsurprising because elements of the small image are likely to show up scattered around the rescaled image so, although it still mostly looks like the big image, it will be somewhat degraded, leading to decreased classifier accuracy as observed. It would be possible to tune the process to minimize the loss of accuracy at the 224x224 scale but we made no attempt to do so in this work.
We tested the effectiveness of defenses by turning on antialiasing during the downscaling process. Both of the classifiers took a small hit in performance even on clean images that had no small image embedded in them. The accuracy loss was about 2 percent and is likely due to the blurring effect caused by antialiasing. Rescaling with antialiasing can also be orders of magnitude slower for large images. For some, these may not be acceptable losses in performance. For others they may be welcome sacrifices for increased security. That security is substantial. With antialiasing on, the embedded images in the downscaling attacks were seen only at levels of random chance and the big images were seen in almost all cases. The big image accuracy for defended attacks was only a couple percent lower than for the clean images that were not attacked at all. The additional loss in accuracy as compared to the antialiased clean images is likely the result of the almost imperceptible small image pixels being blurred into the big image by the antialiasing procedure.

Discussion
Downscaling attacks are nearly one hundred percent effective against vulnerable preprocessing procedures. Knowing that these attacks exist though, they are trivial to detect and they are trivial to defend against with only limited loss in accuracy. Unfortunately, some of the most popular preprocessing procedures are currently vulnerable by default, and some of those that are not can be made vulnerable by an ill-intentioned designer just as easily as they can be hardened. TensorFlow and OpenCV are susceptible by default. Skimage, a package for sklearn, has anti-aliasing on by default but can be made susceptible by setting it to False. Pillow uses a multi-step downscaling so attacking it is harder. PyTorch uses Pillow in torchvision so is less vulnerable, but an alternative torchvision has been written to use the faster OpenCV instead, which is susceptible by default.
The practice of restructuring or filtering inputs for security is relatively new for machine learning but is standard for conventional digital security. SQL injection and cross-site scripting are among the most basic techniques in a conventional hacker's toolkit. They work by inputting commands to be executed rather than just data to be processed, and they have caused vast numbers of breaches. [17] They still cause high profile breaches today, but it has become harder for attackers because defenders can process out malicious inputs in what is known as input sanitization. [18] Machine learning security is still at the stage of learning what attacks are in the realm of the possible and what it even means to sanitize inputs. For example, antialiasing, [19,20] or alternatively, adding noise to inputs, [21,22] has been shown to be a partially effective protection against some adversarial examples. As shown in this paper, ensuring that antialiasing is on can be useful for preventing attacks that use artifacts of the rescaling process. It is likely that more attacks on the inputs are left to be discovered and that both the concept and practice of input sanitization for machine learning has more evolution to do.

Conclusions
Downscaling attacks, that take advantage of the repeating patterns inherent in downsampling an image during resizing, are a vulnerability for image classifiers. An image can be embedded within another image such that, when viewed at two different scales, the two appear completely different. That makes it possible for attackers to completely fool machine vision systems into arbitrary erroneous conclusions. But these attacks can be easily detected and easily defeated, and only some of the preprocessing methods of popular machine learning platforms are vulnerable by default. Sanitizing inputs by simply enabling antialiasing comes at a performance cost of only a couple percent while completely eliminating the threat, at least as posed in the current work. Knowing that these attacks exist is therefore much more than half the battle.