gout

A static git page generator
git clone https://git.bracken.jp/gout.git
Log | Files | Refs | README | LICENSE

commit 43c3f57ddc0e1cfd9c6ad7dd5b554a71d9c340e5
parent d3fc7db161a3d643590ab389d6cdf007bb30bdac
Author: Chris Bracken <chris@bracken.jp>
Date:   Fri, 20 Feb 2026 17:05:53 +0900

git: prevent crash when handling binary files

In gitrepo_walk_tree_files, we determine if a file is binary. If so, we
skip assinging the blob content to the content pointer, since we never
write binary content to HTML/gopher output; instead, we assign an empty
string literal. We do however write the size_bytes with the size of the
binary file.

Later, in gitfile_create, we check if content is non-null and size_bytes
is greater than or equal to zero. If so, we allocate a buffer with size
size_bytes + 1 then memcpy size_bytes from the content char* we assigned
above. In the case of binary files, that was the "" string literal which
is a single byte long.

Diffstat:
Msrc/git/git.c | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/git/git.c b/src/git/git.c @@ -405,7 +405,7 @@ static bool gitrepo_walk_tree_files(git_repository* repo, git_blob* blob = (git_blob*)obj; ssize_t size_bytes = git_blob_rawsize(blob); ssize_t size_lines = -1; - const char* content = ""; + const char* content = NULL; if (size_bytes > kMaxFileSizeBytes) { size_lines = -2; /* oversized file */