From nobody Mon Feb 9 19:25:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98327+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98327+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1673481571; cv=none; d=zohomail.com; s=zohoarc; b=WJH3vcYArcvlQLhRvk7ue8sYtBJ4vQZcnFUBXFuI2fxPptSA5wUKByblIjMZmD6OJ/Ym5Jgf9pd1r3yuDXD9/ynO1puanuqrojtHTbxSCRnAJbcz3FEwW2TQ1KTUbZSshYlg+hTdIWD5wc0aozcqe+M45nWM9g7op/XP4GloTck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673481571; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=1oJMR89+fpv9q7uj9D2mG4d1Rl8p4ZMPrOhrVNpXduc=; b=RQS3DSIqpItX2YD9jIgIgzlZvXRLG0JV4B+88wWHjkqiYvolQKJ6cczFddMTn6ohYIk1w+US44c4HMgV7FMsuDQTOgrcG/Jqz6g7glpWRml70Nsuw1EIe05dzsOmziFU/ugf+kkEpqTmKAXHvzSNOpk/kfQD1QA30ZPXgo8AZ2E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98327+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1673481571499396.12481413886405; Wed, 11 Jan 2023 15:59:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ahrWYY1788612xAlryWlzy1L; Wed, 11 Jan 2023 15:59:31 -0800 X-Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by mx.groups.io with SMTP id smtpd.web10.41551.1673481570329476359 for ; Wed, 11 Jan 2023 15:59:30 -0800 X-Received: by mail-wm1-f47.google.com with SMTP id m3so12151677wmq.0 for ; Wed, 11 Jan 2023 15:59:30 -0800 (PST) X-Gm-Message-State: mh3Lmpw2tdiTFGmZLTLtDvApx1787277AA= X-Google-Smtp-Source: AMrXdXvFu+jRPJB3rsYjZdzb8KQopMgrD+mHAVmQXIjCyD6JV3xE7vVsUhkxbI5dKmMC5rEpfOG7yA== X-Received: by 2002:a05:600c:3c88:b0:3d9:69fd:7707 with SMTP id bg8-20020a05600c3c8800b003d969fd7707mr51424103wmb.2.1673481568562; Wed, 11 Jan 2023 15:59:28 -0800 (PST) X-Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id p21-20020a7bcc95000000b003c65c9a36dfsm19276102wma.48.2023.01.11.15.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 15:59:28 -0800 (PST) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , =?UTF-8?q?Marvin=20H=C3=A4user?= Subject: [edk2-devel] [PATCH 2/2] Ext4Pkg: Fix and clarify handling regarding non-utf8 dir entries Date: Wed, 11 Jan 2023 23:59:19 +0000 Message-Id: <20230111235920.252317-5-pedro.falcato@gmail.com> In-Reply-To: <20230111235920.252317-1-pedro.falcato@gmail.com> References: <20230111235920.252317-1-pedro.falcato@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pedro.falcato@gmail.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673481571; bh=2qRb49nDolIkT/0v18rCYn1nk3Jda2bksME2h5WpTfk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=U0MBhBbiRUXiHcDDscDM1S5YjghH+15OOSkBnToEkVaf52JuomZ2vqy+FSEahMmeXst lcq/9fa2BS2t+NSd4mav5MqgTVyxOaCo8vhOA+WVVaikb/umQ5nmZu3Ob5kNIzvnm+Us+ vNi+ZzPW0s7whcpZ/AciCXOODwblHYncCgE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673481571811100010 Previously, the handling was mixed and/or non-existent regarding non utf-8 dirent names. Clarify it. Signed-off-by: Pedro Falcato Cc: Marvin H=C3=A4user --- Features/Ext4Pkg/Ext4Dxe/Directory.c | 37 ++++++++++++++++++++++------ Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 8 +++--- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dx= e/Directory.c index 6ed664fc632f..ba781bad968c 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -1,7 +1,7 @@ /** @file Directory related routines =20 - Copyright (c) 2021 Pedro Falcato All rights reserved. + Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -16,8 +16,9 @@ @param[in] Entry Pointer to a EXT4_DIR_ENTRY. @param[out] Ucs2FileName Pointer to an array of CHAR16's, of siz= e EXT4_NAME_MAX + 1. =20 - @retval EFI_SUCCESS The filename was succesfully retrieved and conver= ted to UCS2. - @retval !EFI_SUCCESS Failure. + @retval EFI_SUCCESS The filename was succesfully retrieved= and converted to UCS2. + @retval EFI_INVALID_PARAMETER The filename is not valid UTF-8. + @retval !EFI_SUCCESS Failure. **/ EFI_STATUS Ext4GetUcs2DirentName ( @@ -174,10 +175,16 @@ Ext4RetrieveDirent ( * need to form valid ASCII/UTF-8 sequences. */ if (EFI_ERROR (Status)) { - // If we error out, skip this entry - // I'm not sure if this is correct behaviour, but I don't think th= ere's a precedent here. - BlockOffset +=3D Entry->rec_len; - continue; + if (Status =3D=3D EFI_INVALID_PARAMETER) { + // If we error out due to a bad UTF-8 sequence (see Ext4GetUcs2D= irentName), skip this entry. + // I'm not sure if this is correct behaviour, but I don't think = there's a precedent here. + BlockOffset +=3D Entry->rec_len; + continue; + } + + // Other sorts of errors should just error out. + FreePool (Buf); + return Status; } =20 if ((Entry->name_len =3D=3D StrLen (Name)) && @@ -436,6 +443,7 @@ Ext4ReadDir ( EXT4_FILE *TempFile; BOOLEAN ShouldSkip; BOOLEAN IsDotOrDotDot; + CHAR16 DirentUcs2Name[EXT4_NAME_MAX + 1]; =20 DirIno =3D File->Inode; Status =3D EFI_SUCCESS; @@ -505,6 +513,21 @@ Ext4ReadDir ( continue; } =20 + // Test if the dirent is valid utf-8. This is already done inside Ext4= OpenDirent but EFI_INVALID_PARAMETER + // has the danger of its meaning being overloaded in many places, so w= e can't skip according to that. + // So test outside of it, explicitly. + Status =3D Ext4GetUcs2DirentName (&Entry, DirentUcs2Name); + + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_INVALID_PARAMETER) { + // Bad UTF-8, skip. + Offset +=3D Entry.rec_len; + continue; + } + + goto Out; + } + Status =3D Ext4OpenDirent (Partition, EFI_FILE_MODE_READ, &TempFile, &= Entry, File); =20 if (EFI_ERROR (Status)) { diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index 466e49523030..41779dad855f 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -944,11 +944,11 @@ Ext4StrCmpInsensitive ( Retrieves the filename of the directory entry and converts it to UTF-16= /UCS-2 =20 @param[in] Entry Pointer to a EXT4_DIR_ENTRY. - @param[out] Ucs2FileName Pointer to an array of CHAR16's, of size -EXT4_NAME_MAX + 1. + @param[out] Ucs2FileName Pointer to an array of CHAR16's, of siz= e EXT4_NAME_MAX + 1. =20 - @retval EFI_SUCCESS Unicode collation was successfully initialised. - @retval !EFI_SUCCESS Failure. + @retval EFI_SUCCESS The filename was succesfully retrieved= and converted to UCS2. + @retval EFI_INVALID_PARAMETER The filename is not valid UTF-8. + @retval !EFI_SUCCESS Failure. **/ EFI_STATUS Ext4GetUcs2DirentName ( --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98327): https://edk2.groups.io/g/devel/message/98327 Mute This Topic: https://groups.io/mt/96212634/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-