-
Notifications
You must be signed in to change notification settings - Fork 763
FEAT: Add blur_images flag to pyrit.output for safer image rendering #1768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rlundeen2
merged 7 commits into
microsoft:main
from
rlundeen2:users/rlundeen/blur_images
May 22, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4dafb43
FEAT: Add blur_images flag to pyrit.output for safer image rendering
rlundeen2 246981e
Address code review: atomic blurred-file write, configurable dest, mo…
rlundeen2 59554dc
Fix ValueError on cross-drive paths in markdown image formatter
rlundeen2 a2e9768
Address review: text-link fallback, cache-hit log, consistent docstri…
rlundeen2 6fe2d80
Address review + docs: regen 0_output notebook, add jupytext guidance
rlundeen2 df5c5ac
Demo blur_images on real image attack in 0_output notebook
rlundeen2 e670128
Merge remote-tracking branch 'origin/main' into rlundeen2/turbo-potato
rlundeen2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| """ | ||
| Internal image utilities for the output module. | ||
|
|
||
| Used by pretty and markdown conversation printers to apply a Gaussian blur | ||
| to images before they are displayed to a reviewer (the ``blur_images`` flag). | ||
| """ | ||
|
|
||
| import io | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def blur_image_bytes(*, image_bytes: bytes, radius: int = 20) -> bytes: | ||
| """ | ||
| Apply a Gaussian blur to the given image bytes and return blurred PNG bytes. | ||
|
|
||
| Args: | ||
| image_bytes (bytes): The original encoded image bytes. | ||
| radius (int): The Gaussian blur radius. Larger values blur more. | ||
| Defaults to 20. | ||
|
|
||
| Returns: | ||
| bytes: The blurred image encoded as PNG. If blurring fails for any reason, | ||
| returns the original ``image_bytes`` unchanged and logs a warning. | ||
| """ | ||
| try: | ||
| from PIL import Image, ImageFilter | ||
|
|
||
| with Image.open(io.BytesIO(image_bytes)) as image: | ||
| image.load() | ||
| blurred = image.filter(ImageFilter.GaussianBlur(radius=radius)) | ||
| buffer = io.BytesIO() | ||
| blurred.save(buffer, format="PNG") | ||
| return buffer.getvalue() | ||
| except Exception as exc: | ||
| logger.warning(f"Failed to blur image (radius={radius}); returning original bytes. Error: {exc}") | ||
| return image_bytes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.