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

hackmd2cyberblog.py #206

Merged
merged 2 commits into from
Dec 30, 2024
Merged

hackmd2cyberblog.py #206

merged 2 commits into from
Dec 30, 2024

Conversation

bliutech
Copy link
Member

Summary

A utility script to automatically take a HackMD markdown file and prepare it for the Cyber Blog.

Test Plan

Tested locally. Here is a sample run. Note that it gracefully errors with an invalid image capture of the URL (not a markdown image).

$ python3 data/scripts/hackmd2cyberblog.py data/blog/2024-12-12-dummy-blog.md
[*] Downloading images...
[*] Downloading image: https://hackmd.io/_uploads/B1-LPRDXJx.png -> public/images/blog/2024-12-12-dummy-blog/B1-LPRDXJx.png
[*] Downloading image: https://hackmd.io/_uploads/SkWtd0wXJx.png -> public/images/blog/2024-12-12-dummy-blog/SkWtd0wXJx.png
[*] Downloading image: https://hackmd.io/_uploads/Skl6O0PXyx.png -> public/images/blog/2024-12-12-dummy-blog/Skl6O0PXyx.png
[*] Downloading image: https://hackmd.io/_uploads/Hk_zFRwm1g.png -> public/images/blog/2024-12-12-dummy-blog/Hk_zFRwm1g.png
[*] Downloading image: https://hackmd.io/_uploads/BJvmOXnfke.png -> public/images/blog/2024-12-12-dummy-blog/BJvmOXnfke.png
[*] Downloading image: https://hackmd.io/_uploads/rJguJav7Jg.png -> public/images/blog/2024-12-12-dummy-blog/rJguJav7Jg.png
[*] Downloading image: https://hackmd.io/_uploads/BkCeSQnG1x.png -> public/images/blog/2024-12-12-dummy-blog/BkCeSQnG1x.png
[*] Failed to download image: https://hackmd.io/_uploads/BJe_rX2fke.png" width="50%">

Example of a XML file in our seed corpus 
We performed coverage-guided fuzzing via writing a harness with Honggfuzz.

```cpp
#include <cstdint>
#include <string>
#include <tinyxml2.h>

extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size
[*] Downloading image: https://hackmd.io/_uploads/Sy6U1NnM1e.png -> public/images/blog/2024-12-12-dummy-blog/Sy6U1NnM1e.png
[*] Downloading image: https://hackmd.io/_uploads/H1-ehX2Mkx.jpg -> public/images/blog/2024-12-12-dummy-blog/H1-ehX2Mkx.jpg
[*] Downloading image: https://hackmd.io/_uploads/Hyix0mhzye.png -> public/images/blog/2024-12-12-dummy-blog/Hyix0mhzye.png
[*] Downloading image: https://hackmd.io/_uploads/BJ9mFWamJx.png -> public/images/blog/2024-12-12-dummy-blog/BJ9mFWamJx.png
[*] Downloading image: https://hackmd.io/_uploads/rk4R67hz1e.png -> public/images/blog/2024-12-12-dummy-blog/rk4R67hz1e.png
[*] Downloading image: https://hackmd.io/_uploads/HJuiJVnzkl.png -> public/images/blog/2024-12-12-dummy-blog/HJuiJVnzkl.png
[*] Downloading image: https://hackmd.io/_uploads/rJ0aJ4nfyl.png -> public/images/blog/2024-12-12-dummy-blog/rJ0aJ4nfyl.png
[*] Downloading image: https://hackmd.io/_uploads/rkBqjr3z1x.png -> public/images/blog/2024-12-12-dummy-blog/rkBqjr3z1x.png
[*] Done!

If images failed to download, we should not replace the URL in the blog and should gracefully error.
@bliutech
Copy link
Member Author

Added a quick fix to allow failed image downloads to have atomic failures (we shouldn't replace image URLs in the markdown that failed to download) and errors gracefully.

@bliutech bliutech merged commit 280f2a6 into main Dec 30, 2024
@bliutech bliutech deleted the hackmd2cyberblog branch December 30, 2024 23:11
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.

2 participants