DrKLO/Telegram · error

USAGE: %s <correct MD5 sum> <file>

Error message

USAGE: %s <correct MD5 sum> <file>

What it means

The md5cmp utility prints this usage message when invoked with fewer than 3 command-line arguments. It is a standalone CLI program (main) that expects exactly two arguments: a reference MD5 hex string and a file path to hash. The function then computes the MD5 of the file and compares it to the reference. When argc < 3 the program cannot proceed and exits with return code -1.

Source

Thrown at TMessagesProj/jni/mozjpeg/md5/md5cmp.c:39

 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <string.h>
#include "./md5.h"
#include "../tjutil.h"

int main(int argc, char *argv[])
{
  char *md5sum = NULL, buf[65];

  if (argc < 3) {
    fprintf(stderr, "USAGE: %s <correct MD5 sum> <file>\n", argv[0]);
    return -1;
  }

  if (strlen(argv[1]) != 32)
    fprintf(stderr, "WARNING: MD5 hash size is wrong.\n");

  md5sum = MD5File(argv[2], buf);
  if (!md5sum) {
    perror("Could not obtain MD5 sum");
    return -1;
  }

  if (!strcasecmp(md5sum, argv[1])) {
    fprintf(stderr, "%s: OK\n", argv[2]);
    return 0;
  } else {
    fprintf(stderr, "%s: FAILED.  Checksum is %s\n", argv[2], md5sum);
    return -1;

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Pass exactly two arguments after the program name: the 32-character MD5 hex digest as argv[1] and the file path as argv[2].
  2. Verify that any shell variables used for the hash and file path are non-empty before calling md5cmp.
  3. If calling from another program, ensure argc is at least 3 before invoking exec/system.

Example fix

// before
system("md5cmp input.jpg");
// after
system("md5cmp d41d8cd98f00b204e9800998ecf8427e input.jpg");
Defensive patterns

Strategy: validation

Validate before calling

# Validate argument count before invoking md5cmp
if [ $# -lt 2 ]; then
  echo "Error: need <hash> <file>" >&2
  exit 1
fi
md5cmp "$1" "$2"

Prevention

When it happens

Trigger: Running md5cmp with zero or one argument: 'md5cmp', 'md5cmp <file>', or invoking it programmatically via execve/system without supplying both the expected hash string and the file path as argv[1] and argv[2].

Common situations: Shell scripts or build/CI pipelines that call md5cmp but fail to interpolate the hash or file variable; Android NDK test harnesses that invoke the compiled md5cmp binary with missing positional arguments; copy-paste errors when constructing the command line.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/c007b742106e4d7f. Report an issue: GitHub.