From nobody Fri Oct 25 19:37:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1718196330; cv=none; d=zohomail.com; s=zohoarc; b=SuorgyHmmNdzpZf0Oz5MvF8lWe5yl4ljg3y1w7rt/Fo7njBkzxWIHWk+381VPf9FYMDMSIeG3Qpawfw7VEjrMU1FpD/HPa8DsL9kpAGY8YGzEeq1u/3oCoSgjPSNz8TW9xd8kzYskz0UPOjBeMybjziBtdk0/7pvO4PwOM8t/zQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718196330; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Hp73qP7OErp7ZGgPqkAOD0UzQuJ+A1PD/aAVb0gIORA=; b=Ynx3raBbBH0hBX6rYPMqHsY6ABz5UcrGFu6GbgKtZ8TRBaQFoDROrzp1bZUwZSLwXVm0bRPmMBPBn0vcDH9NG5oGyFdVSaIDVAScZ1fjOOUBvTRuPYB9YRuGObgBVb97L9yqQM6Cp2E5OlxJSzh4AVETggPFH+kQWpLTG5UoOSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1718196330230374.6529305074781; Wed, 12 Jun 2024 05:45:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHNLh-0001ET-VA; Wed, 12 Jun 2024 08:45:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sHNLE-0000sD-PR; Wed, 12 Jun 2024 08:44:42 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sHNLB-0004yN-He; Wed, 12 Jun 2024 08:44:39 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70417a6c328so4258118b3a.1; Wed, 12 Jun 2024 05:44:36 -0700 (PDT) Received: from amjad-pc.. ([202.185.212.207]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7042dff35fdsm6928961b3a.131.2024.06.12.05.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 05:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718196275; x=1718801075; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hp73qP7OErp7ZGgPqkAOD0UzQuJ+A1PD/aAVb0gIORA=; b=nm9FwBuKYRPvAAY/aN5ofzu9dQi8+uOFLsQef1uk9a7GXDhIScBUHDqyJBzZrIfBRe fNdmkk1+/0wc81bI+CmYyvUKZ9UrJEjjTTu2zphde5dH5r4mv4uYB3VIVIUInC916nnh oqKrQwhZIbopfwJr5DOIykT9UOCBTKTcZch4vaO4dY4w28Gs+kxpP6doNxJytMdpsGPL 41mbQUse8raleR4EpZjWH2t5BxM1MJ9Lu7Nqa85M2IVZfbYMtumVb6rU4G9zqfCUd3Z7 sZhFG5HGOt7SfYMzxOuDZECXHPGFjomjIrgAP0vTJxFD72wov6g7uSZui190Ntcw0/Zr nHVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718196275; x=1718801075; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hp73qP7OErp7ZGgPqkAOD0UzQuJ+A1PD/aAVb0gIORA=; b=rqXga0p8SoMWB0pkgtntB4qFsHpTuHGBa95Pl8VVsWwlUBJvyD4fWcwv7o8KP2pgOu Wa/7sx/Gf2W+2RHz017So7Ok8HrEqEBZzrqRpLx/5Z6Ss8gfkhPZ45opLISetpv6uxxa y3GFi+ycLhUuFE4fNE7h4g0d4ZWTUQu3XbmG27BWUy9tlNlYWQ6EaUNCoTpLRHqAQlvx TL1R6KhONvbFpFeOc49ZTSKBttmyyQFlA9QWUfQhnfuVeGPTRMMPHlcKRI9kLQkZf8Pp /4c68pYLxgIYuKGwQE2b6x15ZOymJP/PRA5rd68GWAkvDdr9wXte20+wt+EZBb2s5oU/ a/wQ== X-Forwarded-Encrypted: i=1; AJvYcCWr86X+0Hr9pWm+7AhfCz9FjbKFucrE+zlolEZL0poqIeew3oWMCfBsELmY50WGrNJ2yFaVYhtYr38MbhpO22JjtH1lkMk= X-Gm-Message-State: AOJu0YwLz53/6icl3A3doasvmY76mP9SFdnZ1A76xkRogS6dagi72AwH DbcJAiUx7v+dq07MKgUpZMOM3+jP8cNCcWJ+tJ8WzEW11md6JmOJVdFVnACGMCQ= X-Google-Smtp-Source: AGHT+IEBlSi6BYVb/+cQ+MC2K5Njz+PwRmzZrN8mzX1GTUjquKwh35qDppYcIks8cUj+V+pYdZbfdg== X-Received: by 2002:a05:6a00:1146:b0:702:6dc7:2368 with SMTP id d2e1a72fcca58-705bce514aemr1661624b3a.12.1718196275093; Wed, 12 Jun 2024 05:44:35 -0700 (PDT) From: Amjad Alsharafi To: qemu-devel@nongnu.org Cc: Hanna Reitz , Kevin Wolf , "open list:vvfat" , Amjad Alsharafi Subject: [PATCH v5 3/5] vvfat: Fix wrong checks for cluster mappings invariant Date: Wed, 12 Jun 2024 20:43:24 +0800 Message-ID: X-Mailer: git-send-email 2.45.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=amjadsharafi10@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1718196331575100009 Content-Type: text/plain; charset="utf-8" How this `abort` was intended to check for was: - if the `mapping->first_mapping_index` is not the same as `first_mapping_index`, which **should** happen only in one case, when we are handling the first mapping, in that case `mapping->first_mapping_index =3D=3D -1`, in all other cases, the other mappings after the first should have the condition `true`. - From above, we know that this is the first mapping, so if the offset is not `0`, then abort, since this is an invalid state. The issue was that `first_mapping_index` is not set if we are checking from the middle, the variable `first_mapping_index` is only set if we passed through the check `cluster_was_modified` with the first mapping, and in the same function call we checked the other mappings. One approach is to go into the loop even if `cluster_was_modified` is not true so that we will be able to set `first_mapping_index` for the first mapping, but since `first_mapping_index` is only used here, another approach is to just check manually for the `mapping->first_mapping_index !=3D -1` since we know that this is the value for the only entry where `offset =3D=3D 0` (i.e. first mapping). Signed-off-by: Amjad Alsharafi Reviewed-by: Kevin Wolf --- block/vvfat.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 247b232608..b63ac5d045 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1880,7 +1880,6 @@ get_cluster_count_for_direntry(BDRVVVFATState* s, dir= entry_t* direntry, const ch =20 uint32_t cluster_num =3D begin_of_direntry(direntry); uint32_t offset =3D 0; - int first_mapping_index =3D -1; mapping_t* mapping =3D NULL; const char* basename2 =3D NULL; =20 @@ -1942,14 +1941,9 @@ get_cluster_count_for_direntry(BDRVVVFATState* s, di= rentry_t* direntry, const ch =20 if (strcmp(basename, basename2)) copy_it =3D 1; - first_mapping_index =3D array_index(&(s->mapping),= mapping); - } - - if (mapping->first_mapping_index !=3D first_mapping_in= dex - && mapping->info.file.offset > 0) { - abort(); - copy_it =3D 1; } + assert(mapping->first_mapping_index =3D=3D -1 + || mapping->info.file.offset > 0); =20 /* need to write out? */ if (!was_modified && is_file(direntry)) { --=20 2.45.1