13 ms·
Llama.ttf: A font which is also an LLM
- fuglede_ 2y agoVery much inspired this earlier HackerNews post which put Tetris into a font, today we put an LLM and an inference engine into a font so you can chat with your font, or write stuff with your font without having to write stuff with your font. https://news.ycombinator.com/item?id=40737961 https://news.ycombinator.com/item?id=40737961
- hsfzxjy 2y agocool. is there a github repo to produce this thing?
- LeonigMig 2y agothis is over my head
- polshaw 2y agoThe critical part is knowing that TTF fonts can include a virtual machine.. then he pops an llm into that and replaces instances of !!!!!! with whatever the llm outputs.
- abecedarius 2y agoThank you. I wasn't going to watch a video to find out how the LLM actually affects any output.
- oopsallmagic 2y agoNot exactly. Harfbuzz, the font shaping library, has an optional feature to use WASM for shaping. Normal font hinting is much more restricted, precisely because Turing-complete fonts are a horrible idea.
- xrd 2y agoAfter watching part of the video, I believe the world would benefit from a weekly television program where you could tune in each week to watch something weird, brilliant and funny. This would be a great episode #1 for that television show.
- pininja 2y agoThis reminds me of Posy. His channel is so fun, weird, and captivating. https://youtube.com/@posymusic https://youtube.com/@posymusic
- hawski 2y agoWatching his videos is often very calming for me at the same time. Visually striking beauty in simple things, calm narration and pleasing music. I also recommend his Lazy channel.
- pininja 2y agoWatching “Thing on my carpet” is like witnessing curiosity in its purest form
- xrguy 2y agohe is like david attenborough of tech
- btown 2y agoOn the esoteric software engineering side, Tom7 is the channel you're looking for! https://www.youtube.com/@tom7 https://www.youtube.com/@tom7
- nextaccountic 2y agoAlso Paralogical https://youtube.com/@paralogical-dev https://youtube.com/@paralogical-dev
- godelski 2y ago
- electric_mayhem 2y agoWhile cool, technically… From a security perspective today I learned that TrueType fonts have arbitrary code execution as a ‘feature’ which seems mostly horrific.
- samwillis 2y agoNot really, no more so than a random webpage running js/WASM in a sandbox. The only output from the WASM is to draw to screen. There is no chance of a RCE, or data exfiltration.
- asau 2y ago[dead]
- electric_mayhem 2y agoI’m open to your idea, but can you explain in technical terms why a wasm sandbox is invulnerable to the possibility of escape vulnerabilities when other flavors of sandboxes have not been?
- turnsout 2y agoThe risk is that you could have the text content say one thing while the visual display says another. There are social engineering and phishing risks.
- alexvitkov 2y agoIf you control the font, you control the content as well, I don't see the attack vector.
- socksy 2y agoCertain design tools type sites like Canva or Pitch allow you to upload fonts and obviously control the content. They are frequently used by phishers to make official looking phishing pages on a trusted source, leading to a cat and mouse game where the companies try to catch phishing like indicators in the content and flag them up for human review or block immediately. In that case being able to show arbitrary other text would definitely be a hindrance because the scanning software typically looks at the data stored in the database. However I think you don't need a Turing machine to exploit this — you could have a single ligature in a well crafted font produce a full paragraph of text. Perhaps there's an alternative vector where someone's premade font on a site that doesn't allow font uploading can be exploited to make arbitrary calculations given certain character strings. Maybe bitcoin mining, if you could find a way to phone home with the result
- closetkantian 2y agoThis is really cool, but I'm left with a lot of questions. Why does the font always generate the same string to replace the exclamation points as he moves from gedit to gimp? Shouldn't the LLM be creating a new "inference"? As an aside, I originally thought this was going to generate a new font "style" that matched the text. So for example, "once upon a time" would look like a storybook style font or if you wrote something computer science-related, it would look like a tech manual font. I wonder if that's possible.
- closetkantian 2y agoSo, another poster cleared up my first question. It's probably because the seed is the same. I think it would have been a better demo if it hadn't been, though.
- thomasfromcdnjs 2y agoBut having the same "seed" doesn't guarantee the same response from an LLM, hence the question above.
- wavemode 2y agoI fail to understand how an LLM could produce two different responses from the same seed. Same seed implies all random numbers generated will be the same. So where is the source of nondeterminism?
- furyofantares 2y agoI believe people are confused because ChatGPT's API exposes a seed parameter which is not guaranteed to be deterministic. But that's due to the possibility model configuration changes on the service end and not relevant here.
- dragonwriter 2y agoBarring subtle incompatibilities in underlying implementations on different environments, it does, assuming all other generation settings (temperature, etc.) are held constant.
- wiradikusuma 2y agoSo how do you copy the output?
- jonathaneunice 2y agoI never imagined a future in which PDFs talked back. Now I can.
- anthk 2y agoPostScript files are dynamic code. You can create polygons dynamically with commands. And, of course, font FX's, styles, elipses... Also, there's a ZMachine interpreter (text adventure player) written in PostScript which can play Zork and some libre games such as Calypso with just GhostScript, the PostScript interpreter most software use to render PostScript files.
- fourthark 2y agollama.pdf when?
- bandrami 2y agoPostScript is Turing complete and your PDF reader is a PostScript interpreter. So, yeah, potentially any PDF is instructions to a general-purpose computer.
- layer8 2y agoPostScript is deprecated in PDF though.
- hi-v-rocknroll 2y agoOlder versions of PDF files and readers don't know or care about what happened later. PDFs also did shady shit like being able to embed JavaScript actions and other files. They also became Turing complete when they adopted Type 4 functions in PDF 1.3 that still aren't deprecated in 2.0. LaTeX subsumed most of the human authoring uses of PS where it was used in academia.
- polshaw 2y agoThis is cool, as far as a practical issue though (aside from the 280gb TTF file!) is that it makes it incompatible with all other fonts; if you copy and paste your "improved" text then it will no longer say what you thought it did. It just alters the presentation, not the content. I guess you would have to ocr to get the content as you see it. I was wondering why this was never used for an simpler autocorrect, but i guess that's why. Also perhaps someone more educated on LLMs could tell me; this wouldn't always be consistent right? Like "once upon a time _____" wouldn't always output the same thing, yes? If so even copying and pasting in your own system using the correct font could change the content.
- Retr0id 2y agoIf there's any randomness involved in inference, it ought to be deterministic as long as the same seed is used each time.
- furyofantares 2y agoIs there even any possibility of using a different seed? I'd doubt the WASM shaper has accesss to any source of non-determinism.
- magnat 2y ago> if you copy and paste your "improved" text then it will no longer say what you thought it did It's not a bug, it's a feature - a DRM. Your content can now be consumed, but cannot be copied or modified - all without external tools, as long as you embed that TTF somehow. Which kind of reminds me of a PDF invoices I got from my electricity provider. It looked and printed perfectly fine, but used weird codepoint mapping which resulted in complete garbage when trying to copy any text from it. Fun times, especially when pasting account number to a banking app.
- mbb70 2y agoThis is while pretty much all software that extracts structured data from PDFs throws away the text and just OCRs the page. Too many tricks with layouts and fonts.
- xg15 2y ago> The font shaping engine Harfbuzz, used in applications such as Firefox and Chrome, comes with a Wasm shaper allowing arbitrary code to be used to "shape" text. Has there already been a proposal to add scripting functionality to Unicode itself? Seems to me we're not very far from that anymore...
- reportgunner 2y agoThat sounds disgusting.
- magicalhippo 2y agoUnicode OS when?
- DemocracyFTW2 2y agoConsidering the actual complexity of rendering e.g. Urdu in decent, native-looking way you presumably do want some Turing-complete capabilities at least in some cases, cf "One handwritten Urdu newspaper, The Musalman, is still published daily in Chennai.[232] InPage, a widely used desktop publishing tool for Urdu, has over 20,000 ligatures in its Nastaʿliq computer fonts." (https://en.wikipedia.org/wiki/Urdu#Writing_system https://en.wikipedia.org/wiki/Urdu#Writing_system) Edit—the OP uses this exact use case, Urdu typesetting, to justify WASM in Harfbuzz (video around 6:00); seems like Urdu has really become the posterchild for typographic complexity these days
- crazygringo 2y agoTo Unicode? Good god please no. Unicode is just codepoints. I shudder to think what adding scripting support to that would even mean. Maybe you meant adding it to OpenType?
- xg15 2y agoI was being sarcastic, but yes, I meant unicode...
- crazygringo 2y ago
- simonw 2y ago> The font shaping engine Harfbuzz, used in applications such as Firefox and Chrome, comes with a Wasm shaper allowing arbitrary code to be used to "shape" text. In that case could you ship a live demo of this that's a web page with the font embedded in the page as a web font, such that Chrome and Firefox users can try it out without installing anything else?
- chazeon 2y agoAs shown in the video, the font is 280 GB, so opening such a page will practically be a nightmare, especially if you are on cellular.
- yreg 2y agoThe font is 60MB. > Usage: Just download llama.ttf (60 MB download, since it's based on the 15M parameter TinyStories-based model demoed above) and use it like you would any other font.
- binwiederhier 2y agoIn the video he shows that the font file size is 290GB, so I would assume that's a little prohibitive.
- codezero 2y agoThat’s only for a 70B param LLM. The one he includes is 15M params and weighs about 60MB. Not tiny, but doable.
- bandrami 2y agoThat's smaller than Noto
- azeirah 2y agoThat's LLaMa-3-70B. The demo he gives at 6:09 is tinystories-15m, which is 30.4MB, so you'd only have to add the font to that (80~KB?) https://huggingface.co/nickypro/tinyllama-15M/tree/main https://huggingface.co/nickypro/tinyllama-15M/tree/main
- yourfriendpalsy 2y agoInteresting idea, but needs to be ported to the Typescript type system.
- fefe23 2y ago[flagged]
- deleted 2y ago[deleted]
- Xlythe 2y agoIt seems like it'd be possible to, instead of typing multiple exclamation points, have one trigger-character (eg. ). And then replace that character visually with an entire paragraph of text, assuming there aren't limits to the width of a character in fonts. I suppose the cursor and text wrapping would go wonky, though. You could also use this to make animated fonts. An excuse to hook up a diffusion model next?
- Lockal 2y ago"animated fonts" - not really; all meaningful applications not only calculate shaping once, they also aggressively cache the result (mentioned in https://robert.ocallahan.org/2024/06/browser-engine.html https://robert.ocallahan.org/2024/06/browser-engine.html) But things like this might be possible (for now): https://gwern.net/dropcap https://gwern.net/dropcap
- bitwize 2y ago> The font shaping engine Harfbuzz, used in applications such as Firefox and Chrome, comes with a Wasm shaper allowing arbitrary code to be used to "shape" text. Oh, this can't be used for nefarious purposes. What could POSSIBLY go wrong?!
- oopsallmagic 2y agoThe engine isn't built with it by default, so this is a non-issue.
- lacoolj 2y agoHello. I'm Dr. Sheldon Cooper. And welcome to Sheldon Cooper Presents: Fun with Fonts
- exe34 2y agoyour engineers were so busy finding out if they could, they never stopped to ask if they should!
- rhyjyrtjhtyn 2y agoThe author categorizes this as "pointless" but some things I can think of is being able to create automated workflows within an app that didn't previously allow it or had limited scope and then creating app interoperability with other app's using the same method.
- ComputerGuru 2y agoYou mean via wasm hinting in general or embedded llm in specific? Because I don’t see why you need an llm for that.
- Syzygies 2y ago[flagged]
- raincole 2y agoIt's a really random comment that isn't relevant to the parent post. The post isn't even about image-generating AI.
- deleted 2y ago[deleted]
- pk-protect-ai 2y agoI will never allow my linux to update my fonts ever again ... Arbitrary code execution in its finest form.
- tcsenpai 2y agoI may be doing this wrong but...the font provided just install as OpenSans and does not provide any functionality at least in mousepad or LibreOffice Writer. I am talking about the 90mb one
- fuglede_ 2y agoYeah, sorry, that could have been clearer, I added a few more instructions. Basically, chances are that even if you've got Harfbuzz running, you're still running a version with no Wasm runtime. If so, chances are you can get away with building it with Wasm support, then add the built library to LD_PRELOAD before running the editor.
- tcsenpai 2y agoThat was useful. I have indeed compiled and installed wasm-micro and now meson build it successfully. Tho "meson compile -C build" returns an error about not finding "hb-wasm-api-list.hh". Do you have any experience of that? EDIT: Nevermind. Using the exact commits you linked give another error (undefined reference to wasm_externref_ref2obj). I give up
- fuglede_ 2y agoAnother font connoisseur put together a script here that might be helpful: https://github.com/hsfzxjy/Harfbuzz-WASM-Fantasy/blob/master/scripts/build_harfbuzz.sh https://github.com/hsfzxjy/Harfbuzz-WASM-Fantasy/blob/master...
- tcsenpai 2y agoManaged to build it using "-DWAMR_BUILD_REF_TYPES=1" And it works! Now is time to dive deep :)
- chena12 2y ago[flagged]
- Dwedit 2y agoI thought the Bad Apple font was really neat, but this is just too much.
- NayamAmarshe 2y agoThis is the coolest thing I've seen this week.
- geor9e 2y ago>build Harfbuzz with -Dwasm=enabled and build wasm-micro-runtime, then add the resulting shared libraries, libharfbuzz.so.0.60811.0 and libiwasm.so to the LD_PRELOAD environment variable before running a Harfbuzz-based application such as gedit or GIMP It'd be lovely if someone embedded the font in a website form to save us all the trouble of demoing it
- erk__ 2y agoIt would not be of much use as no browser enables this experimental feature. So unless you somehow build a wasm build of Harfbuzz with the feature enabled and embed it on there nothing will happen.
- choppaface 2y agoAnd thank goodness it’s disabled, or we could have another JBIG2 https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-into-nso-zero-click.html?m=1 https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-i...
- pennomi 2y agoYeah I know these posts are all funny use cases, but all I can see are font-based security nightmares.
- curtisf 2y agoAre there _any_ generally available consumer applications (document viewers, printers, obscure browsers, ...) that use a TTF font renderer with the WASM feature enabled?
- Lockal 2y agoAccording to demo, this feature has no opt-in, so if Android/iOS/any Linux distro ships with "better fonts feature for LibreOffice" it will be enabled in every text editor/browser/electron app, up to systemd blue screen of death.
- jraph 2y ago(Show HN)
- chena12 2y ago[dead]
- ranger_danger 2y agoThis is terrifying.
- bastien2 2y agoWell this definitely won't get exploited at all or lead to new strict limits on what Harfbuzz/WASM can do
- chena12 2y ago[dead]
- lxgr 2y agoWASM sandboxing is pretty good! Together with the presumably very limited API with which this can communicate with the outside world, I wouldn't be too concerned. To me, it's a great reminder that the line between well-sandboxed turing-complete execution environments and messy implementations of decoders for "purely declarative" data formats can be quite blurry. Said differently, I'd probably trust Harfbuzz/WASM more than the average obscure codec implementation in ffmpeg.
- pbmahol 2y agoIs there scientific proof of above claim such as "WASM sandboxing is pretty good!" ? At least most if not all ffmpeg decoders and demuxers are fuzzed all the time and any found issue is addressed.
- lxgr 2y agoFuzzing is good, robust sandboxing is better, I'd argue. There's just a much smaller surface area to cover for the latter. > Is there scientific proof of above claim such as "WASM sandboxing is pretty good!" ? I'm not aware of quantitative studies, but just from a design perspective, the surface that a WASM runtime presents seems intrinsically easier to defend than that of, say, the full Unix userspace that ffmpeg instances usually run in. Anecdotally, many high-profile iOS and Android vulnerabilities originated in some more or less obscure codec implementation.
- zharknado 2y agoMy takeaway is that if you can efficiently simulate rendering raster graphics with text ligatures, you could run Doom in a TTF. Right?
- petters 2y agoThe page links to https://www.coderelay.io/fontemon.html https://www.coderelay.io/fontemon.html which is a game embedded into a font. Playable in the browser.
- freitasm 2y agoStopped watching when the demo showed the letter O with a slash. That would confuse me a lot. I am an old timer and expect the zero to have it.
- samatman 2y agoIt's not possible to write the letter Ø without a slash. The slash is part of the letter.
- anthk 2y agoA Z Machine in a TTF font, anyone?
- tcsenpai 2y agoAfter your help and troubleshooting, I am happy to notify you that your work has been archived (https://archive.tunnelsenpai.win/archive/1719179042.512455/index.html https://archive.tunnelsenpai.win/archive/1719179042.512455/i... and in the Internet Archive). Thanks!
- bbor 2y agoWow, this is incredible. OP you (I?) should train a few models with different personalities/tasks and pair them with the 5 GitHub Monaspace fonts accordingly, allowing people in multifont programs to easily get different kinds of help in different situations. Lots of little ideas sparked by this… in general, I think this a good reminder that we are vastly underestimating fonts in discussions of UI (and, it appears, UX in full!)
- kylehotchkiss 2y agoIs this the AI hype cycle equivalent of in browser crypto mining? (once the file size goes down a little)
- est 2y agofirst time I've heard of harfbuzz. So we could expect latex.ttf very soon?
- stgiga 2y agoWebAssembly in fonts doesn't sound very secure, coming from someone who is certified in cybersecurity and has spent years doing font stuff.
- lifthrasiir 2y agoBut probably much better than custom VM like TrueType bytecodes or embedded PostScript...
- ohmyiv 2y agoYes, that's the general consensus in the comments. It doesn't even sound safe to me and I'm not a full security pro. But OP did it as a PoC/for fun. It's okay to have fun still.
- lewispollard 2y agoIt's not what OP did that isn't safe, it's the mechanism that he used in HarfBuzz.
- ohmyiv 2y agoSorry for not disclosing everything that could go wrong, but you seemed to have missed my point while trying to be exact.
- lewispollard 2y agoAgain, it's not that anything the OP did is unsafe or could go wrong.
- ohmyiv 2y agoAgain, thanks for missing my point.
- lewispollard 2y ago
- ilrwbwrkhv 2y agoThis is so so awesome! One of the best things I have seen so far this year.
- amai 2y agoDoes this mean fonts are Turing complete nowadays? Sounds like a pretty bad idea for security.
- michaelt 2y agoApparently the font can only embed WASM, which is sandboxed so it can't do anything except turning a buffer of codepoints into glyphs and positioning them. Of course, back in the 1990s Java and Flash were supposed to be sandboxed. So who knows?
- exDM69 2y agoTrueType fonts have had a Turing complete virtual machine (almost?) since the beginning. It is used for "hinting" to allow partially colored pixels at low resolutions to remain legible. It's basically a program that decides whether to color a pixel or not to allow fine tuning of low resolution rasterization. This isn't used as much today with modern large resolutions where we can get decent image quality from just rasterizing the font outline with anti aliasing. This example, however, is using wasm embedded to ttf fonts which is not the same as ttf hinting byte code.
- amai 2y ago> TrueType fonts have had a Turing complete virtual machine (almost?) since the beginning. It is used for "hinting" to allow partially colored pixels at low resolutions to remain legible. It's basically a program that decides whether to color a pixel or not to allow fine tuning of low resolution rasterization. That sounds like an awful idea, too. I think a font file should describe the fonts form, but it should not describe how it is gonna be rendered. That should be up to the render engine of the device that is going to display the font (printer driver, monitor driver...). But I guess this idea is from a time when people were still using bitmap fonts.
- exDM69 2y agoYou need to remember that when TrueType fonts were introduced, a typical display resolution was 640x480 to 800x600 on a 13-15" display. If you rasterize the Bezier curve outline of a ttf font at that resolution, you will have very crooked characters without anti aliasing and very blurry with AA. At the same time the same font files needed to look good on print paper with a very different DPI setting. It's a compromise between bitmap and outline fonts. Not ideal but it delivered good results on display and on paper at the time. The hinting engine is not (?) used that much any more with large resolutions where we can comfortably just rasterize the outline with some AA and have good results.
- fitsumbelay 2y agoexcellence
- UncleOxidant 2y agoabout 1/3 way through the video and I'm getting the impression this is an elaborate joke.
- UncleOxidant 2y agoCan someone explain why HarfBuzz isn't a potentially serious security vulnerability? Couldn't someone create a .ttf file that looks like one of the standard .ttf files but includes similar capability to this llama.ttf to execute arbitrary code?
- progbits 2y agohttps://webassembly.org/docs/security/ https://webassembly.org/docs/security/