MCPcopy Create free account
hub / github.com/git/git / verify_buffer_safe

Function verify_buffer_safe

refs/packed-backend.c:492–506  ·  view source on GitHub ↗

* We want to be able to compare mmapped reference records quickly, * without totally parsing them. We can do so because the records are * LF-terminated, and the refname should start exactly (GIT_SHA1_HEXSZ * + 1) bytes past the beginning of the record. * * But what if the `packed-refs` file contains garbage? We're willing * to tolerate not detecting the problem, as long as we don't produce

Source from the content-addressed store, hash-verified

490 * these checks fails.
491 */
492static void verify_buffer_safe(struct snapshot *snapshot)
493{
494 const char *start = snapshot->start;
495 const char *eof = snapshot->eof;
496 const char *last_line;
497
498 if (start == eof)
499 return;
500
501 last_line = find_start_of_record(start, eof - 1);
502 if (*(eof - 1) != '\n' ||
503 eof - last_line < snapshot_hexsz(snapshot) + 2)
504 die_invalid_line(snapshot->refs->path,
505 last_line, eof - last_line);
506}
507
508/*
509 * When parsing the "packed-refs" file, we will parse it line by line.

Callers 1

create_snapshotFunction · 0.85

Calls 3

find_start_of_recordFunction · 0.85
snapshot_hexszFunction · 0.85
die_invalid_lineFunction · 0.85

Tested by

no test coverage detected