Summary
imgaug's BackgroundAugmenter class trusts data received over a multiprocessing queue and deserializes it using Python's pickle module without validation.
If an attacker can influence the data sent to this queue, they can supply a malicious pickle payload that executes arbitrary code in the context of the worker process, resulting in local or remote code execution depending on how imgaug is deployed.
Affected context
This vulnerability affects applications that use imgaug's BackgroundAugmenter (in multicore.py) with multiprocessing enabled to augment images in background worker processes.
It becomes relevant when the data placed on the internal multiprocessing queue can be influenced—directly or indirectly—by untrusted or semi-trusted sources, shared infrastructure, or user-supplied scripts that control the augmentation pipeline.
Exploit preconditions
- Attack surface: The multiprocessing queue used by BackgroundAugmenter to exchange augmentation tasks and data.
- Required access: Ability to inject or manipulate items placed onto this queue (e.g., via a malicious script in a shared environment, compromised job orchestration, or any code path that forwards untrusted data into the augmentation pipeline).
- Trigger point: The
_augment_images_worker()method inmulticore.pycallspickle.loads()(directly or indirectly) on queued data during normal processing. - Why exploitation is possible: Python's pickle format is code-capable; deserializing attacker-controlled pickle data lets an attacker define arbitrary object graphs whose construction can run attacker-chosen code, and the implementation does not apply any safety checks, type validation, or trust boundary enforcement before deserialization.
Why this happens
The core issue is the use of Python's general-purpose pickle deserialization on data whose authenticity and integrity are not guaranteed.
BackgroundAugmenter relies on a multiprocessing queue and uses pickle to transfer arbitrary Python objects between processes.
This pattern assumes the queue contents are fully trusted, but when that assumption is violated, it maps directly to CWE-502: Deserialization of Untrusted Data.
Pickle is inherently unsafe for untrusted input because object reconstruction can invoke arbitrary callables; without strict trust boundaries or format restrictions, any attacker-controllable data reaching pickle.loads() becomes an execution vector.
Potential impact
- Execution of arbitrary code in the worker process context
- Compromise of the application using imgaug (e.g., image processing service, ML training pipeline)
- Unauthorized access to local files, environment variables, or credentials available to the worker
- Use of the compromised process as a pivot for lateral movement within the hosting environment
- Data tampering or poisoning of image datasets or model training inputs
General mitigation guidance
Effective mitigation focuses on removing or strictly constraining unsafe deserialization and tightening trust boundaries around inter-process communication:
- Prefer serialization formats that are data-only and not code-capable (e.g., JSON, MessagePack, or protocol buffers) for transferring information between processes.
- If pickling cannot be avoided, ensure the queue is only ever fed by strongly trusted code paths, under the same administrative control boundary as the worker processes.
- Constrain the types of objects that can traverse the queue by using simple, well-defined data structures (e.g., primitive types, dicts, lists) and validate structure and types before processing.
- Isolate augmentation workers using least-privilege principles (reduced OS permissions, minimal filesystem access, no unnecessary network connectivity) so that an exploited worker has limited impact.
- Apply defense-in-depth controls such as process-level sandboxing, containerization, or mandatory access controls to reduce damage if deserialization is abused.
How teams detect issues like this
Detecting this class of vulnerability typically involves a combination of code-centric and operational techniques:
- Static analysis: Flag usage of
pickle.loads,pickle.load, or similar serialization APIs when the input source is not clearly constrained to trusted in-memory objects or private channels. - Code review: Look for multiprocessing or IPC patterns where complex objects are sent over queues or pipes, especially in libraries like imgaug, and verify that only trusted producers can write to those channels.
- Security policy enforcement: Establish coding guidelines that prohibit pickle for untrusted data and require safer serialization formats; enforce these via pre-commit hooks or CI checks.
- Runtime monitoring: Where feasible, monitor for unexpected child processes, abnormal file access, or network connections from augmentation workers that could indicate code execution beyond intended behavior.

