19 ms·
You can do a lot with an empty file
- amenghra 5y agoThe infinitely profitable program: http://www.peetm.com/blog/?p=55 http://www.peetm.com/blog/?p=55
- ndotl 5y agoYou can even win an IOCCC and be remembered nearly thirty years later: https://github.com/c00kiemon5ter/ioccc-obfuscated-c-contest/blob/master/1994/smr.hint https://github.com/c00kiemon5ter/ioccc-obfuscated-c-contest/...
- memco 5y agoIf I recall correctly one of the most popular third party apps first released for the iPhone was a flashlight app that was a blank app with an icon and a name. Slightly more code than any of those under the hood, but I feel the idea is the same.
- blamazon 5y agoStraying further from empty-file-ness, but in a similar vein of low-effort apps in the early days of the iPhone was the controversial I Am Rich, which still makes me giggle: https://en.wikipedia.org/wiki/I_Am_Rich https://en.wikipedia.org/wiki/I_Am_Rich >I am rich >I deserv [sic] it >I am good, >healthy & successful
- Cthulhu_ 5y agoWhile this was clearly an experiment etc, a "I am rich" showing off is still prevalent in most games these days with high ticket in-game purchases. Either of the variant that gives your character or base or whatever an appearance trait, or pay-to-win items that puts you high up on the leaderboards.
- blamazon 5y agoI find it ironic that Apple, which is now infamous for 700 dollar computer wheels and 999 dollar display stand, etc, was the party to swiftly ban such an experiment.
- version_five 5y agoThis could be a direct ancestor of NFTs
- hoosieree 5y agoAn NFT way ahead of its time.
- Rendello 5y agoThis one deserves a mention as well: > Send Me To Heaven (officially stylized as S.M.T.H.) is an Android application developed by Carrot Pop which measures the vertical distance that a mobile phone is thrown. Players compete against each other by seeking to throw their phones higher than others, often at the risk of damaging their phones. https://en.wikipedia.org/wiki/Send_Me_To_Heaven https://en.wikipedia.org/wiki/Send_Me_To_Heaven
- junon 5y agohttps://github.com/c00kiemon5ter/ioccc-obfuscated-c-contest/blob/master/1994/Makefile#L85 https://github.com/c00kiemon5ter/ioccc-obfuscated-c-contest/... The compilation command line for anyone curious. Clever.
- renonce 5y agoSo the participant was in fact allowed to change the compiler command so `gcc` isn't even used...? I had wondered how gcc would compile an empty file.
- ncmncm 5y agoGcc is perfectly happy to compile an empty file. But the linker does not find a "main" symbol in its output, so complains.
- junon 5y agoIt was probably an oversight in the rules, as the entry's readme alludes to. They knew that by submitting this, the rules would be amended to be much more strict. Whether that includes requiring a compiler of some sort, I'm not sure. I doubt it - I would imagine the file just has to be 1 or more bytes now.
- JoeAltmaier 5y agoMisread the title: "You can do a lot with an empty rifle". Whole 'nother topic.
- dredmorbius 5y agoClearly following the "everything is a rifle" philosophy of OS development. Though one notes that rifle-based storage incorporates the pipe and executable.
- derefr 5y ago> It's probably something funny involving how the interpreter is spun up - looking for #! and that kind of stuff. Is this actually a result of exec(2) treating the file as text? My intuition is something else: that this is instead a long-inherited compatibility shim for very, very old executable object formats (e.g. COM, a.out) for systems without virtual memory — where in these executable formats, you’d expect to be able to have the instruction pointer “run off the end” of an executable, with the effect of that being to cleanly quit the program — rather than trapping on an undefined op, hitting a HLT, or getting anything like a protection fault. The OS would ensure control returns to it after program “run-out” execution, by the OS exec(2)-alike syscall ensuring it writes a RET op or the like just past the end of the memory it copied the loaded program into, before jumping to the beginning of said memory. Mind you, jumps into “hyperspace” (beyond where anything bothered to write; perhaps beyond where any chips are mapped on the bus) won’t take you to a clean RET op written by the OS, but rather likely to a 00 (active-high logic) or FF (active-low logic) op. Which is precisely why CPU designers usually make the relevant one of those for their logic into the ISA’s HLT op! (Fun fact: even bytecode abstract machines do this. Read “off the end” of an Ethereum contract and you get 00 bytes — and, no surprise, 00 is the EVM ISA HLT op.)
- unnouinceput 5y agoQuote: "Awesome, right? This works just fine on Macs as well." Well, doesn't work on Windows though. I get "Access is denied" when I try to run an empty .exe. Even when I do it with an elevated prompt I get the same. Yeah, so..¯\_(ツ)_/¯
- krallja 5y agoTry EMPTY.BAT from CMD.COM, or EMPTY.PS1 from PowerShell. A zero-byte executable doesn’t work on macOS either. This article is about command shell behavior, not UI shell behavior.
- thunderbong 5y agoI don't know how executables work on Windows but I'm guessing that the shell expects a different kind of 'success' response?
- unnouinceput 5y agoThe thing is that the executable is not ran at all. You get the error coming from OS directly before, not after it fake-ish exited like explained in article for Linux/MacOS. I think this was neatly explained by Ray in one of his older entries. The OS tries to load the .exe's header, then assign heap+stack according to that header, and only then will start the execution at entry point pointed by the header. So, empty file -> no header -> OS complains -> no execution + above error.
- JoBrad 5y agoMaybe an empty com file will work?
- unnouinceput 5y agoNope, same error message.
- pjmlp 5y agoWindows isn't a UNIX clone, at very much an VMS inspired OS.
- 4oo4 5y agoThis is hilarious, though interestingly if you try to see what's going on with gdb or strace it actually errors out properly. $ strace ./empty execve("./empty", ["./empty"], 0x7ffe0156c9d0 /* 61 vars */) = -1 ENOEXEC (Exec format error) strace: exec: Exec format error +++ exited with 1 +++ (I'm not very good with gdb so maybe this is wrong) gdb empty "0x7ffd34c7dc30s": not in executable format: file format not recognized (gdb) exec-file No executable file now I think what's actually happening is that bash is `source`-ing the file, so that's what causes the exit code to be zero.
- infotogivenm 5y agoIt is indeed a shell behavior, specified in POSIX sh. > If the execve() function fails due to an error equivalent to the [ENOEXEC] error defined in the System Interfaces volume of IEEE Std 1003.1-2001, the shell shall execute a command equivalent to having a shell invoked with the pathname resulting from the search as its first operand, with any remaining arguments passed to the new shell, except that the value of "$0" in the new shell may be set to the command name. If the executable file is not a text file, the shell may bypass this command execution. In this case, it shall write an error message, and shall return an exit status of 126. https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html#tag_02_09_01_01 https://pubs.opengroup.org/onlinepubs/009604499/utilities/xc...
- garaetjjte 5y agoDoes file that don't contain any LF is valid "text file", though?
- bombcar 5y agoWhich likely means the zero byte /bin/true is SLOWER than a compiled correct one because it has to first ENOEXEC and then reexecute via the shell.
- alpb 5y ago> Does this mean the smallest /bin/true is actually an empty file? Yes. It used to be. Here's the history from Rob Pike https://twitter.com/rob_pike/status/966896123548872705 https://twitter.com/rob_pike/status/966896123548872705
- TedShiller 5y agonone of the posts on that blog make sense
- encryptluks2 5y agoI often feel the same way. I feel like I'm reading the blog of a tech newbie at the level of discovering `symlinks` for the very first time. The title is overrated and seems clickbait-y and so I was left disappointed.
- vasco 5y agoMy favorite way to create an empty file and impress ladies at bars is: "> emptyfilename"
- pwiecz 5y agoI've misread the title as "You can do a lot with an empty life", and clicked eagerly hiping to learn how to deal with the feeling of emptiness in your life.
- spc476 5y agoAn empty file was also the infinitely profitable program: http://peetm.com/blog/?p=55 http://peetm.com/blog/?p=55 On CP/M, it was useful to rerun the previous program that was still in memory.
- rolling_robot 5y agohttps://youtu.be/To93v46PllQ?t=444 https://youtu.be/To93v46PllQ?t=444
- ddaalluu2 5y agoWho is this Rachel and why does she use HN as her personal blog outlet?
- rurban 5y agoit should be 'touch true'. shortest true ever.
- tpoacher 5y agoI use empty files extremely successfully as a task management system Total commander allows you to assign custom icons to extensions and lots of other things that make this very handy.
- yakubin 5y ago> Does this mean the smallest /bin/true is actually an empty file? That was exactly the implementation of /bin/true in Unix v7: <https://github.com/v7unix/v7unix/blob/master/v7/bin/true https://github.com/v7unix/v7unix/blob/master/v7/bin/true>
- re 5y agoThis subject has been posted about a few times on HN, along with some looks at the evolution of the implementation of the command: https://hn.algolia.com/?dateRange=all&page=0&prefix=false&query=%22bin%2Ftrue%22&sort=byPopularity&type=story https://hn.algolia.com/?dateRange=all&page=0&prefix=false&qu... Here's the most recent, with the most comments: https://news.ycombinator.com/item?id=28257666 https://news.ycombinator.com/item?id=28257666
- aidenn0 5y agoIt also means that the shortest quine is an empty file.
- Cloudef 5y agoMeanwhile GNU coreutils version of /bin/true ... https://github.com/coreutils/coreutils/blob/master/src/true.c https://github.com/coreutils/coreutils/blob/master/src/true....
- mikepurvis 5y agoFair, though most of that is the fact that it has --help output and also that the same source covers both true and false. But yeah.
- e3bc54b2 5y agoIIRC GNU's /bin/true also has massive performance advantage. I am not able to find it presently, but an old post tried to reverse engineer it, and turns out it does caching and whatnot to get something like 12 GBps throughput. Edit: I was wrong, it is actually GNU 'yes': https://www.teddit.net/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/?st=j3v3iw3c&sh=5651ea3c https://www.teddit.net/r/unix/comments/6gxduc/how_is_gnu_yes...
- emerged 5y agoI ran into this lately when I hadn’t validated a successful file transfer. The script ran to completion against all expectations. Obviously you should check a hash before executing a download anyway, but this was just some automated build code.
- mcphage 5y agoThis reminds me of the story about the "go.com" program someone sold for £5, which was just an empty file: http://peetm.com/blog/?p=55 http://peetm.com/blog/?p=55
- jaclaz 5y agoHistorically there was also NaDa: https://web.archive.org/web/20140813120630/http://www.bernardbelanger.com/computing/NaDa/index.php https://web.archive.org/web/20140813120630/http://www.bernar... but is bloated in comparison, being one byte in size.
- skrtskrt 5y agothis is fantastic
- dylan604 5y agoIt's probably the cleanest code you will ever see.
- kragen 5y agoIt was very useful!
- nonrandomstring 5y agoAFAICS some other interpreters, perl, python, ruby, tcl are happy to return a 0 exit code if invoked on an empty file.
- kayodelycaon 5y agoPretty much. They ran all the code that was in the file without errors.
- remram 5y agoEmpty files are common in Python: a __init__.py is required (or was) to mark a directory as a Python package, allowing its content to be imported.
- deathanatos 5y agoThere is a bit of a difference to me between the behavior described in the article (directly executing with ./foo) and "sh foo" or "python foo". In the former case, I would have expected a shebang to be needed, so that execv(2) would know what to execute (as it needs some magic bytes to determine what loader to use, or whether to treat it as a script, and I didn't think it had a fallback). (And I'm right… in a sense. The actual behavior is more complex & more horrifying, and covered in other comments.)
- gnarula 5y agoIn case anyone's curious, in absence of a shebang (#!), Linux [1] returns an ENOEXEC to the execve syscall, after which the invoking program (the shell) handles the failure. Usually shells default to running the file as a shell script with itself as argv0. [1] https://github.com/torvalds/linux/blob/3e732ebf7316ac83e8562db7e64cc68aec390a18/fs/binfmt_script.c#L41 https://github.com/torvalds/linux/blob/3e732ebf7316ac83e8562...
- abbeyj 5y agoThis can lead to an interesting situation where a program will work if launched by a shell (or by another program that uses `execlp`), but will fail if it is launched with a different variant of `exec`. For example: $ touch empty $ chmod a+x empty $ ./empty # Works $ valgrind -q ./empty # Works $ timeout 10s ./empty # Works $ /usr/bin/time ./empty # Works $ perl -e 'exec("./empty") or die' # Works $ python -c 'import subprocess; subprocess.check_call("./empty", shell=True)' # Works $ python -c 'import subprocess; subprocess.check_call("./empty")' # Fails ... OSError: [Errno 8] Exec format error $ ruby -e 'exec "./empty"' # Fails -e:1:in `exec': Exec format error - ./empty (Errno::ENOEXEC) from -e:1 $ strace ./empty # Fails execve("./empty", ["./empty"], 0x7fff6639f3a0 /* 84 vars */) = -1 ENOEXEC (Exec format error) strace: exec: Exec format error +++ exited with 1 +++ It can be quite fun to track down why a program executes successfully and then later fails to execute, with no changes made to the program in between.
- jjnoakes 5y agoI knew this about the programming languages which wrap execution in a shell, but I never knew that execlp/execvp/execvpe handled ENOEXEC internally and wrapped the command in a shell too. TIL!
- donio 5y agoA fun consequence of this is that running a python script that doesn't have the shebang will mysteriously hang with a crosshair cursor until you click the mouse. When the shell encounters the first "import foo" line it tries to run ImageMagick's "import" utility which tries to take a screenshot of the selected window.
- wyldfire 5y ago> as far as the package database was concerned, it was "rpm -qV" is a command that will audit the signatures of a package's contents. I don't know if dpkg has something similar but it would be cool if it did.
- acranox 5y agodebsums https://manpages.ubuntu.com/manpages/jammy/en/man1/debsums.1.html https://manpages.ubuntu.com/manpages/jammy/en/man1/debsums.1...
- wyldfire 5y agomd5? Is 'jammy' a remarkably old platform? I hope so. But regardless of the signature algorithm, thanks for sharing the mechanism.
- Dylan16807 5y ago> md5? Is 'jammy' a remarkably old platform? I hope so. Jammy comes out next month. Though if you encounter an md5 second preimage attack that's pretty impressive.
- userbinator 5y ago2002 according to the copyright. But it also has this note: debsums is intended primarily as a way of determining what installed files have been locally modified by the administrator or damaged by media errors and is of limited use as a security tool.
- Wowfunhappy 5y ago> Yesterday's post about "pipefail" also involved some systems which treated an empty file as a valid file. This turns out to be surprisingly common. I don't understand why this is surprising. Of course an empty file is a valid file, just like an empty piece of paper is a valid piece of paper. I mean, yes, a piece of paper is also different. Paper is a physical object with volume and weight; a file is a sequence of bytes representing information. But, step out of your programmer mindset for a moment. Almost every user interface represents files as objects containing information, not information itself.
- dataflow 5y agoI think she meant "an empty file is a valid file to some programs that should ostensibly expect otherwise", but worded in a way that ends up being confusing.
- wvenable 5y agoI think the implication isn't merely "valid file" but rather it's "valid file of a particular type". The example given is that an empty file is a valid executable. It might also be a valid CSV file but not a valid Excel file.
- Wowfunhappy 5y agoThanks, yes, that makes much more sense!
- floodle 5y agoI know what you mean, I also took a double-take when I read that sentence. But when I read a bit further I decided it was just poor phrasing initially.
- AnimalMuppet 5y agoOK, but this is about an empty file being a valid program file (though the title doesn't make that clear). I mean, an empty sheet of paper is also a valid list of instructions, but that's at least slightly weirder than it being a valid sheet of paper.
- geocrasher 5y agoThis is a great trick for a lot of things. For example, if a web server is getting lots of attacks against a particular URL, one could block that URL or otherwise make it inaccessible. That'll turn it into a 404 or 500, or whatever. But it turns out that a 200 is much faster, and so replacing the target with a blank file is faster than denying it. This is particularly true with xml-rpc.php. Instead of just removing it, empty it. Problem solved.
- yabones 5y ago204 is the fastest, since it is exactly zero bytes of content. For most webservers you don't even need to point it at a specific file, just say "return 204" and that's enough. I've done this numerous times to "whitehole" bad scanners or bots with great success :)
- ketralnis 5y agoWhat does it mean for a 200 to be faster? I guess I can see some framework or CDN reasons that might be so but it doesn’t feel like an inherent thing
- CaliforniaKarl 5y agoImagine if you have a site that displays some sort of custom content when a client is hitting a 404 error. Even if it’s just a static page, the web browser still has to follow the code path and open it. Even if it caches the page internally, it still has to regularly check if the file updated on disk. The amount of time spent by the web browser is fairly small, but the parent comment mentioned it in context of an attack, so that small per-page effort multiplied by many connections makes for more of a substantial load.
- Karellen 5y agoBut why can't you just return a 404 with no content instead of a 200 with no content?
- 5y ago