Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF829C4332F for ; Wed, 28 Dec 2022 22:54:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0A1648545E; Wed, 28 Dec 2022 23:54:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=collins.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collins.com header.i=@collins.com header.b="BX/xl5VJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5832F85461; Wed, 28 Dec 2022 23:54:17 +0100 (CET) Received: from mx0b-00105401.pphosted.com (mx0b-00105401.pphosted.com [67.231.152.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C3F3685454 for ; Wed, 28 Dec 2022 23:54:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=collins.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=63611ae917=brandon.maier@collins.com Received: from pps.filterd (m0074334.ppops.net [127.0.0.1]) by mx0b-00105401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 2BSMre5J015352 for ; Wed, 28 Dec 2022 22:54:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=collins.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=POD051818; bh=jglndsqEhrVhsmV1j85FzO6lCnB7ZIvc3hPT9F2IVc8=; b=BX/xl5VJrZzP/sB+IY4Owwl6aJ7gIqReejWm1G0PPeHwOE4OxiAcvZJ5lj9rXjdeaq0D HjVl+jHhgRU1zRt3rz7GbIxuYRnHgrY3aSoxcmeKE73YF7ApQk8QjB0q4oilU4l7qHgj 6xp7ghawGzlePGS5zf45BYbYMr8tSyAAhx02nxkUUO84IEC9c9SXuC9ZjuvY+GUBCTgY gzNdPQ1HCdzKuyMLhAlJgS2/7M6IXHAiwg/oCvVjCKASNigcg6HM3CTn51kjlLkOteC9 n8X+daKpVtZom7mp7e5fVxC+bQXt6s6ECstAJA25C52rM5lUh59Zhg1N5kiLpaud0l6g WA== Received: from xnwpv37.utc.com ([167.17.239.17]) by mx0b-00105401.pphosted.com with ESMTP id 3mpd7fye93-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 28 Dec 2022 22:54:12 +0000 Received: from qusnwafg.utcapp.com (qusnwafg.utcapp.com [10.161.48.103]) by xnwpv37.utc.com (8.16.1.2/8.16.1.2) with ESMTPS id 2BSMsCEx013306 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 28 Dec 2022 22:54:12 GMT Received: from ciulimr02.rockwellcollins.com ([10.172.224.19]) by qusnwafg.utcapp.com (8.16.1.2/8.16.1.2) with ESMTPS id 2BSMsBZF020514 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 28 Dec 2022 22:54:11 GMT X-Received: from kirk.rockwellcollins.lab (kirk.rockwellcollins.lab [10.148.204.208]) by ciulimr02.rockwellcollins.com (Postfix) with ESMTP id 797D4200F5; Wed, 28 Dec 2022 16:54:11 -0600 (CST) From: Brandon Maier To: u-boot@lists.denx.de Cc: Brandon Maier Subject: [PATCH 1/2] test: compression: check with trailing garbage in input Date: Wed, 28 Dec 2022 16:53:51 -0600 Message-Id: <20221228225352.38364-1-brandon.maier@collins.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: X5aMOCFeMD_3-IHqRb4ykjqfxVQYvMp_ X-Proofpoint-ORIG-GUID: X5aMOCFeMD_3-IHqRb4ykjqfxVQYvMp_ X-Proofpoint-Spam-Details: rule=outbound_default_notspam policy=outbound_default score=0 suspectscore=0 adultscore=0 impostorscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 phishscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212280196 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The Linux kernel appends 4 bytes to the end of compressed kernel Images containing the uncompressed image size. They are used to make self-decompressing Images easier. However for archs that don't support self-decompression, like ARM64, U-Boot must be able to decompress the image with the garbage data. The existing decompressors already support this. This unit test was added while working on zstd support as upstream zstd will error if there is garbage data in the input buffer, and special care was needed to support this. Signed-off-by: Brandon Maier --- test/compression.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/compression.c b/test/compression.c index 82e29c9b86b..6c2a43fbed7 100644 --- a/test/compression.c +++ b/test/compression.c @@ -350,6 +350,15 @@ static int run_test_internal(struct unit_test_state *uts, char *name, buf->orig_size) == 0); errcheck(((char *)buf->uncompressed_buf)[buf->orig_size] == 'A'); + /* Uncompresses with trailing garbage in input buffer. */ + memset(buf->uncompressed_buf, 'A', TEST_BUFFER_SIZE); + errcheck(uncompress(uts, buf->compressed_buf, buf->compressed_size + 4, + buf->uncompressed_buf, buf->uncompressed_size, + &buf->uncompressed_size) == 0); + errcheck(buf->uncompressed_size == buf->orig_size); + errcheck(memcmp(buf->orig_buf, buf->uncompressed_buf, + buf->orig_size) == 0); + /* Make sure compression does not over-run. */ memset(buf->compare_buf, 'A', TEST_BUFFER_SIZE); ret = compress(uts, buf->orig_buf, buf->orig_size, -- 2.39.0