CVSS Vector: AV:L/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H (5.0/4.9)
Until quite recently, the cloud storage provider, Dropbox, made use of a novel algorithm for losslessly compressing JPEG image files called "lepton". This allowed them to store those images in a way that utilized approximately 22% less disk space, in aggregate.
The tool, which Dropbox has released as open source, is robustly designed with security in mind. Untrusted data, for the most part, is handled by separate subprocesses, which are "run within seccomp to disable all system calls except read and write of already-open file descriptors." This is enough to severely curtail the scope of any attempted remote code execution attacks, and seems like an eminently sensible design decision for a tool designed to handle vast quantities of untrusted user-controlled data.
The bug in question, however, is a simple denial of service vulnerability. It is possible to craft a JPEG file that will throw Lepton's seccomp-enclosed compression verification step -- which ensures that the file has been compressed losslessly by attempting to decompress it again and compare it with the original -- into an infinite loop. The master process hangs indefinitely while it waits for this verification process to run to completion.
The critical lines of code appear to be in the function encode_eobrun() in src/lepton/jpgcoder.cc:
5349:int encode_eobrun( abitwriter* huffw, huffCodes* actbl, unsigned int* eobrun )
5350-{
5351- unsigned short n;
5352- unsigned int s;
5353- int hc;
5354-
5355-
5356- if ( (*eobrun) > 0 ) {
5357- while ( (*eobrun) > actbl->max_eobrun ) {
5358- huffw->write( actbl->cval[ 0xE0 ], actbl->clen[ 0xE0 ] );
5359- huffw->write( E_ENVLI( 14, 32767 ), 14 );
5360- (*eobrun) -= actbl->max_eobrun;
5361- }
5362- s = uint16bit_length((*eobrun));
5363- dev_assert(s && "actbl->max_eobrun needs to be > 0");
5364- if (s) s--;
5365- n = E_ENVLI( s, (*eobrun) );
5366- hc = ( s << 4 );
5367- huffw->write( actbl->cval[ hc ], actbl->clen[ hc ] );
5368- huffw->write( n, s );
5369- (*eobrun) = 0;
5370- }
5371-
5372-
5373- return 0;
5374-}
Note that the struct field actbl->max_eobrun is checked only after the while loop! And it turns out to be possible to craft a JPEG file that Lepton will compress into a faulty LEP file, which when processed again by Lepton will fail to populate the max_eobrun field of the actbl struct, leaving it at 0. Since this block of code is designed to loop until *eobrun is zero, and each iteration, in this case, subtracts zero from *eobrun, the value referenced by *eobrun never reaches zero and the loop never ends. This gives us our denial of service vulnerability.
Deprecation Notice
90 days ago, we reported this issue to Dropbox, and they have since responded by deprecating the Lepton tool and archiving the tool's open source github repository at <https://github.com/dropbox/lepton>, citing this particular DoS vulnerability in their deprecation notice, as shown in the git diff between the current HEAD of the master branch and the commit where we discovered this vulnerability (429fe880d331b49a5be08b4d8dc762cbada6d4ca):
$ git diff origin master Δ README.md ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ─────┐ • 1: │ ─────┘
⚠️ Deprecation Notice for the Dropbox Lepton project
Dear Lepton users and developers,
Thank you so much for using and contributing to Lepton over the years! We’ve recently realized that we no longer have sufficient resources to adequately support this project. This includes providing timely fixes to bugs and vulnerabilities such as those that were [recently reported to us](https://github.com/dropbox/lepton/issues/158). While we did ensure that the reported vulnerabilities don’t affect our internal use of Lepton, we unfortunately don’t have the capacity to properly fix these and future issu→ If you would like to continue using Lepton, please check out various forks of the project (or start your own!) or alternatively consider switching to other lossless compression methods such as [Brotli](https://dropbox.tech/infrastructure/lossless-compression-with-brotli) or to modern image formats such as [WebP](https://en.wikipedia.org/wiki/WebP) or [JPEG XL](https://en.wikipedia.org/wiki/JPEG_XL).
# Lepton Lepton is a tool and file format for losslessly compressing JPEGs by an average of 22%.
Proof of Concept
The attached JPEG file is sufficient to trigger the denial of service vulnerability in the current, now-archived version of Lepton.