Skip to content
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

Added image to custom circuit appearance #1924

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Toshayo
Copy link

@Toshayo Toshayo commented Dec 11, 2023

Added image shape to custom circuit appearance. The image has one attribute: the URL. It is downloaded and shown when the circuit is rendering.
I've also added an option to disable the image download.

Copy link
Member

@maehne maehne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be at least reviewed/tested also from @BFH-ktt1. The suggested changes look sensible to me. It would be nice if you could provide also some documentation and use case / screenshot of this functionality to demonstrate its usage.

@Toshayo
Copy link
Author

Toshayo commented Dec 12, 2023

The new shape works like a normal rectangle. You can scale it using squares at the corners. When you enter an URL into the image's properties, logisim downloads and shows the image.
The option to disable image load is located in preferences, layout settings. It is true by default :
image

Here is a random example :
image

@maehne
Copy link
Member

maehne commented Dec 12, 2023

IMHO, it is problematic if images get downloaded dynamically during loading of circuit files. It could cause hard to handle security risks. Restricting it to only local files may be a bit safer. Ideally, the image should be saved as part of the circuit file. In any case, some security risks remain due to manipulated image files causing buffer overflows and similar things.

@maehne
Copy link
Member

maehne commented Dec 12, 2023

Thanks anyway for your explanations and illustrative screenshots. I can see a certain value in this functionality, but I am not sure whether it is worth the risk. Therefore, I would like feedback by other regular contributors to this project, i.e., @BFH-ktt1, @davidhutchens, @MarcinOrlowski, @R3dst0ne, @TheEvilSkeleton.

@Toshayo
Copy link
Author

Toshayo commented Dec 12, 2023

Thanks for your fast feedback!

IMHO, it is problematic if images get downloaded dynamically during loading of circuit files. It could cause hard to handle security risks. Restricting it to only local files may be a bit safer. Ideally, the image should be safes as part of the circuit file. In any case, some security risks remain due to manipulated image files causing buffer overflows and similar things.

I imagine some solutions for this :

  • The easiest is to set image loading to false by default. Not too secure as it makes the feature useless.
  • Add a URL whitelist.
  • Proceed like in some tools like Microsoft's Word, ask the user to load or not remote content.
  • Use local files as you've suggested.
  • Save image pixels in the .circ file. I think it's not the best option as it will increase file size and make it less readable.

I would like to know your opinion about these ideas.

@davidhutchens
Copy link
Member

I agree with @maehne about the use of network URLs to load files during startup. We have not used networks for any functionality, and I don't think loading images is a reason to start now. At the least, this would cause .circ files to behave differently if no network is available. At worst, it might have security implications. Therefore, I would reject your first three bullet points. I also note that for Mac users, we actually say in the documentation that you can deny network access to our program without causing any problems.

That leaves using local files to load the original image and either linking to the local file or saving the image in the .circ file. We currently have the ability to link to libraries and other .circ files in our local file system. So linking to image files would not be much different. As with the libraries, it is best to use relative paths so a directory can hold the .circ files and images that are linked. This would provide easy sharing of the package.

Copy link
Member

@maehne maehne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the raised security concerns. Personally, I would tend to embed the images inside the circuit file. However, it is important that they get encoded in a way that the circuit files remain pure text XML files.

@Toshayo
Copy link
Author

Toshayo commented Dec 17, 2023

The most common way to encode an image in text is base64, but having images in circ files will increase it size. Even if we resize it, an 640x480 random color JPG image takes about 0.5MB in base64.

@MarcinOrlowski
Copy link
Member

I'd not worry the size much, frankly speaking. Since feature is optional to use, if size is a concern, one can just not use it.

@maehne
Copy link
Member

maehne commented Dec 17, 2023

I would be OK with base64. Is 640 x 480 pixels or bigger really the size of images, you would typically assign to a circuit symbol? In any case, base64 doesn't prevent using a compressed image format such as PNG or JPEG. In any case, a vector format -- ideally SVG would be preferred to guarantee good quality.

Maybe, the intent/requirements for this enhancements should be first analysed/discussed a bit more in detail before deciding where/how to store the image data.

dependabot bot and others added 4 commits December 24, 2023 18:20
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@Toshayo
Copy link
Author

Toshayo commented Dec 24, 2023

Changes :

  • Replaced loading images from internet by URL to loading image from local system.
  • Storing the image in base64 form. Image is not resized/modified. If it is just a circuit image like in the example, it should not affect project file size too much.
  • Removed option to allow downloads as it is no more useful

@Toshayo Toshayo requested a review from maehne April 24, 2024 09:48
@maehne
Copy link
Member

maehne commented Apr 26, 2024

@Toshayo: Thanks for this additional work on your PR to incorporate our feedback. Could you please provide a small test case using your feature in form of a ZIP archive including a CIRC file + the used image(s)? This would facilitate testing on our side.

@Toshayo
Copy link
Author

Toshayo commented Apr 26, 2024

Here is same example as a little higher: logisim_image_example.zip
The image is encoded via base64 into the CIRC file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants