| 1 | /* |
| 2 | Copyright @ 2018 ImageMagick Studio LLC, a non-profit organization |
| 3 | dedicated to making software imaging solutions freely available. |
| 4 | |
| 5 | You may not use this file except in compliance with the License. You may |
| 6 | obtain a copy of the License at |
| 7 | |
| 8 | https://imagemagick.org/license/ |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <Magick++/Functions.h> |
| 18 | #include <Magick++/ResourceLimits.h> |
| 19 | #include <Magick++/SecurityPolicy.h> |
| 20 | |
| 21 | #ifndef FUZZ_MAX_SIZE |
| 22 | #define FUZZ_MAX_SIZE 2048 |
| 23 | #endif |
| 24 | |
| 25 | static bool IsInvalidSize(const size_t size,const size_t min = 1) |
| 26 | { |
| 27 | if (size < min) |
| 28 | return(true); |
| 29 | if (size > 8192) |
| 30 | return(true); |
| 31 | return(false); |
| 32 | } |
| 33 | |
| 34 | class FuzzingInitializer |
| 35 | { |
| 36 | public: |
| 37 | FuzzingInitializer() |
| 38 | { |
| 39 | // Disable SIMD in jpeg turbo. |
| 40 | (void) putenv(const_cast<char *>("JSIMD_FORCENONE=1")); |
| 41 | |
| 42 | Magick::InitializeMagick((const char *) NULL); |
| 43 | Magick::SecurityPolicy::anonymousCacheMemoryMap(); |
| 44 | Magick::SecurityPolicy::anonymousSystemMemoryMap(); |
| 45 | Magick::SecurityPolicy::maxMemoryRequest(128000000); |
| 46 | Magick::SecurityPolicy::maxProfileSize(1000000); |
| 47 | Magick::ResourceLimits::memory(1000000000); |
| 48 | Magick::ResourceLimits::map(500000000); |
| 49 | Magick::ResourceLimits::width(FUZZ_MAX_SIZE); |
| 50 | Magick::ResourceLimits::height(FUZZ_MAX_SIZE); |
| 51 | Magick::ResourceLimits::listLength(16); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | FuzzingInitializer fuzzingInitializer; |
| 56 | |
| 57 | #if defined(BUILD_MAIN) |
| 58 | #include "encoder_format.h" |
| 59 | |
| 60 | EncoderFormat encoderFormat; |
| 61 | |
| 62 | #define FUZZ_ENCODER encoderFormat.get() |
| 63 | #endif |