Fix BGR encoding, thread safety, path traversal, and count limit in SavePicture service#3
Draft
Copilot wants to merge 3 commits intothagdorn/picture_saverfrom
Draft
Fix BGR encoding, thread safety, path traversal, and count limit in SavePicture service#3Copilot wants to merge 3 commits intothagdorn/picture_saverfrom
Copilot wants to merge 3 commits intothagdorn/picture_saverfrom
Conversation
…sal, count limit, log message Co-authored-by: TomHagdorn <85993250+TomHagdorn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add ROS 2 service for saving pictures with picam
Fix BGR encoding, thread safety, path traversal, and count limit in SavePicture service
Mar 11, 2026
Contributor
|
@copilot Why even use mutexes in the first place. I can also just grab the next fram right? No need to always have one on hand |
…ttern Co-authored-by: TomHagdorn <85993250+TomHagdorn@users.noreply.github.com>
Author
You still need a mutex — Each shot records the current frame sequence number, then calls |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
SavePictureservice had several correctness, safety, and security issues: wrong image encoding label,latest_image_updated only via a self-subscription that couldn't run while the service callback was sleeping, unboundedcount, arbitrary filesystem write paths, and a misleading log message.Changes
cv::imdecodereturns BGR — encoding was incorrectly declared asrgb8, nowbgr8image_sub_). Each shot inhandle_save_picturenow waits up to 5 s for the next genuinely fresh frame from the read thread using astd::condition_variableand a sequence number (latest_image_seq_).notify_all()is called inside the lock after each frame is stored inhandle_image_message. This guarantees every save receives a new camera frame rather than a potentially stale buffered one.save_directoryin the request is now validated before use:..components are rejectedweakly_canonical()is used to confirm the resolved path stays under the configured basesave_directory_(guards against symlink escapes)count > MAX_PICTURE_COUNT(100) is rejected with an error response/picam_client/save_pictureSavePicture.srv: Comments updated to document the relative-path constraint and max count🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.