🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #769

[PATCH] config: read the bytes of a blob as unsigned characters

#769
From: Olof Fairbrook
Date: Sun, 18 Oct 2026 15:24
89 lines
10999 bytes
"git config --blob" and the other readers of config from memory get
each byte from config_buf_fgetc(), which returns it as a plain "char".
Where "char" is signed, as on x86, a byte 0xff comes back as -1, which
is EOF, and any byte from 0x80 up as a negative number.  So the parser
stops at a byte 0xff and silently ignores the rest of the blob:

  $ printf '# caf\377\n[some]\n\tkey = value\n' >config
  $ git config --blob=$(git hash-object -w config) --list
  $

and a blob that starts with a UTF-8 byte order mark is a "bad config
line 1", because the code that skips the mark compares with unsigned
bytes.  A config file has neither problem, as getc() returns unsigned
bytes.  ".gitmodules" read from a commit goes through the same reader.

This has been so since config_buf_fgetc() was added in 1bc888193e
(teach config --blob option to parse config from database,
2013-07-12).

Return the byte as an unsigned char, as getc() does.
config_buf_ungetc() checks that it is given back the byte it read; it
now compares with the byte as an unsigned char too, or a CR followed
by such a byte would hit its BUG().

Signed-off-by: Olof Fairbrook <olof.fairbrook@gmail.com>
---
 config.c               |  4 ++--
 t/t1307-config-blob.sh | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/config.c b/config.c
index d9019e7e6c..fbe873274e 100644
--- a/config.c
+++ b/config.c
@@ -92,7 +92,7 @@ static long config_file_ftell(struct config_source *conf)
 static int config_buf_fgetc(struct config_source *conf)
 {
 	if (conf->u.buf.pos < conf->u.buf.len)
-		return conf->u.buf.buf[conf->u.buf.pos++];
+		return (unsigned char)conf->u.buf.buf[conf->u.buf.pos++];
 
 	return EOF;
 }
@@ -101,7 +101,7 @@ static int config_buf_ungetc(int c, struct config_source *conf)
 {
 	if (conf->u.buf.pos > 0) {
 		conf->u.buf.pos--;
-		if (conf->u.buf.buf[conf->u.buf.pos] != c)
+		if ((unsigned char)conf->u.buf.buf[conf->u.buf.pos] != c)
 			BUG("config_buf can only ungetc the same character");
 		return c;
 	}
diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 5cb546dd00..e2c0883350 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -72,6 +72,27 @@ test_expect_success 'can parse blob ending with CR' '
 	test_cmp expect actual
 '
 
+test_expect_success 'a byte 0xff does not end a blob' '
+	test_commit --printf FF config "# caf\\377\\n[some]\\n\\tkey = value\\n" &&
+	echo value >expect &&
+	git config --blob=HEAD:config some.key >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'a byte 0xff after a CR in a blob' '
+	test_commit --printf CRFF config "# a\\r\\377\\n[some]\\n\\tkey = value\\n" &&
+	echo value >expect &&
+	git config --blob=HEAD:config some.key >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'can parse blob starting with a byte order mark' '
+	test_commit --printf BOM config "\\357\\273\\277[some]\\n\\tkey = value\\n" &&
+	echo value >expect &&
+	git config --blob=HEAD:config some.key >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'config --blob outside of a repository is an error' '
 	nongit test_must_fail git config --blob=foo --list
 '

base-commit: a018953688f1b10bddf91bff8747068f5f4746a4
-- 
2.43.0
Technical Details
Message-ID: <20261018152426.2716899-1-olof.fairbrook@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72341-linux-kernel-git=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72341-linux-kernel-git=dewy.ru
From: olof.fairbrook@gmail.com (Olof Fairbrook)
Newsgroups: linux.kernel.git
Subject: [PATCH] config: read the bytes of a blob as unsigned characters
Date: Sun, 18 Oct 2026 17:24:26 +0200
Organization: Usenet Network
Message-ID: <20261018152426.2716899-1-olof.fairbrook@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3356955"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:g16gIYlzQNPqoggGzOB6nrzOieQ= sha256:28CSxZJHiwCfRGB7rbO6HXy7KPb+XiJJ0mB5kAvgg4I=
	sha1:jpIwL64Zb4fiw2BXYqfl/4dd+r0= sha256:bGC6Zq4ptJ/K+TyDQShokmE6C4wj3O12hJd8CKW8IbU=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 903A111082B; Sun, 18 Oct 2026 18:25:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Fwvj0-Yobm6r;
	Sun, 18 Oct 2026 18:24:59 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72341-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 4DAE111082F; Sun, 18 Oct 2026 18:24:50 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by tor.lore.kernel.org (Postfix) with ESMTP id 8973F322A8; Sun, 18 Oct 2026 15:24:47 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B2A64D0A00;
	Sun, 18 Oct 2026 15:24:43 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lBaefqxH"
X-Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E3034D0CC7
	for <git@vger.kernel.org>; Sun, 18 Oct 2026 15:24:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1792337080; cv=none; b=tMTmu01yXZxQWSJ/dStNQTncRcKZZiVtL2HK8jLWxoKXQLVqjhKXtWPPuei1oTls/04IICt+9ajR8/GSdtB/Ef2mhg4brcBEoBZYL5h1k4e5IQleuvVggZt1tm/S3hIVZsGcCQfeB/11jogD7I/O3yKr2vKczR5qLOCe+3NRVLA=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1792337080; c=relaxed/simple;
	bh=B9Ubekv2QTpX8w7yS0cxYO9gNeslWf4s4cc2Gpq6fUc=;
	h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HeuRSsZLoJA+BeRUgAKzUI6Pid3Bbc8kEiDhQ8RDOpK3e0Xvb8h0wDu+FUzfrCN7oQ7EeGP02v3Gw3uoOyS3Yp2ukK+n+rBQROm79clhPAs9QeQWFRYlRCNjKi1qtQnpR4x96wWKUvtfDtLnENGO19GsbXuCVE3bsBCpZcHaw7Y=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lBaefqxH; arc=none smtp.client-ip=209.85.208.172
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-3ab1a37faaeso1962841fa.0
        for <git@vger.kernel.org>; Sun, 18 Oct 2026 08:24:37 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792337075; x=1792941875; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=wKBO35TTYhQRByiH9MuB6ioAbFHKLdCW4cjUUx8OU3k=;
        b=lBaefqxHdUBpDoXoAdtVBCF2EIXx2vT/lmMpcFiI9gzIjgWS3sAqdkNeu8y/dHUSX2
         cBvWzpCL2Spf1Cb2rgqrS8ZhwoljVdPU/4AE4bh1NbhOtMk26HHrHLVE7brK5E4LgpPb
         AcpTnlTt88N7RxeMxwtf8t7MbU9UkoEPdhyEh/iMD2fZykyREWjRAYPxKb3B01cNC5Jw
         KoUHiMDcsaR11yWXYXvPjb/EqOXvBehfa5VwulxYBxxDvEwcbiJ5Me4s7xxnTj1ivS9Q
         tud3VzmRaj3GESFIhsbp4lSYcPjAulx4h3/79UwMGv7QRoHCIHztMqjTWuo92XA84aKC
         mr7w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792337075; x=1792941875;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=wKBO35TTYhQRByiH9MuB6ioAbFHKLdCW4cjUUx8OU3k=;
        b=c6MPIee3RHkGStCoQ0x1dbmG2IyXtpVTzVk4HosTY3DtTxK1ugQdFuvK1KerhHOyrZ
         p6KH+Z89qw3zchP/rSs1quccCVDc1UAIFp6YV/pT/2ICa7d1DSLeO2E0lKOdFopcogoF
         baR9+ILO5Fml/nda8muduOXE6D/NscBiYtBK2kRGFlvn3Xu5236xfDlgiBNKboowdOyN
         E6dzD8eVBCGFdI7NtOyEcoucfraxeq5RHFrjAM4qgVNTw5cisiZOZaRhJ2x/YDZxLwmB
         UOQfsEZ38wEpA4vqMxHp/mKLBlQ5YS/RwzLBjtDOoVegXrZPPYa5m3fa/prY16bA55yZ
         wWtQ==
X-Gm-Message-State: AFq9FYL2jWTdmso1KKJxSLXsdwz2wfJsbS5l50aq4T/vu9HxNhYY3ISH
	QOHD0lBa2hp2F9f1fAx4SRv002t4JAoXXJmm0T0HrezW+0P/dmKzYAUjsaCaA2ZZk9s=
X-Gm-Gg: AYBFou2eOmyAYuxHJmDR8PEEvAiLULISDo3edLVZkSOUiBsG03N93kQPHbsC6OZlMzB
	uscsKkyunBQRiMJ5GpnTgitglV+G5PnSaE4Ww2LY8iPoWSA8a3IVBUDB5VPg4v+qmB/0IQ+Tc1w
	gfyT3L2nsZlyTY3lVP/PiCeB40Q4r61phX0XAjyG4nLuBMquT2EpxE2GqN7GBBNjVtivBdSPj83
	nFsL3A+japoqaOUbusNM4E6AzZZDX9LejJZZkjktoPaJLXd3OVNgMWUAa8hQ6Zh/Gwt6KmuWLKW
	W7BOi6C2gUMU47b9kRwJUE62xmlJsbgWaOvt72SrEa/bP5Qcs+ZPl/3304lGbp8iYms9AShUJIn
	wPDptRgBy9s3LJxPU1gSizNnGjpV2JXFENvj5+WDXmIWH5pHUtm+y+d1H5DSTBMSAFNtQyNTsl+
	2ozVGLfM94Q9VLklQQlzzROnHG81456tCMheNfbg7+2hIeVao3S0nSNQySoP8aNZeFK1aaDBgjK
	Kg+s9q070mvsl938r//fkfqWRw2tCCZBzm82kEIUg==
X-Received: by 2002:a05:6512:3f20:b0:5ba:3579:3673 with SMTP id 2adb3069b0e04-5be50a88e2emr1512541e87.5.1792337075053;
        Sun, 18 Oct 2026 08:24:35 -0700 (PDT)
X-Received: from Iris-HRQ6HW3.. (78-71-217-218-no600.tbcn.telia.com. [78.71.217.218])
        by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5be4a3fd03dsm1483225e87.11.2026.10.18.08.24.34
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 18 Oct 2026 08:24:34 -0700 (PDT)
X-Cc: Patrick Steinhardt <ps@pks.im>,
	Jeff King <peff@peff.net>,
	Heiko Voigt <hvoigt@hvoigt.net>,
	Olof Fairbrook <olof.fairbrook@gmail.com>
X-Mailer: git-send-email 2.43.0
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>