From 6773c3c4cd90e66cab43655a24fb9bdc07eaf782 Mon Sep 17 00:00:00 2001 From: Shamser Ahmed Date: Thu, 7 Mar 2024 17:06:32 +0000 Subject: [PATCH] HPCC-31416 CDistributedSuperFile::querySubFile may return incorrect subfile Querying CDistributedSuperFile for a subfile that doesn't exist returned a subfile instead of throwing an exception. By not throwing an error, incorrect code that calls querySubFile may be appear to work. This fix modifies querySubFile so that it throws an exception when the subfile number is not valid. Signed-off-by: Shamser Ahmed --- dali/base/dadfs.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dali/base/dadfs.cpp b/dali/base/dadfs.cpp index 6e2c6b5f113..057bef01cbc 100644 --- a/dali/base/dadfs.cpp +++ b/dali/base/dadfs.cpp @@ -6271,20 +6271,22 @@ class CDistributedSuperFile: public CDistributedFileBase virtual IDistributedFile &querySubFile(unsigned idx,bool sub) override { CriticalBlock block (sect); - if (sub) { + if (sub) + { + unsigned subfilen = idx; ForEachItemIn(i,subfiles) { IDistributedFile &f=subfiles.item(i); IDistributedSuperFile *super = f.querySuperFile(); if (super) { unsigned ns = super->numSubFiles(true); - if (ns>idx) - return super->querySubFile(idx,true); - idx -= ns; + if (ns>subfilen) + return super->querySubFile(subfilen,true); + subfilen -= ns; } - else if (idx--==0) + else if (subfilen--==0) return f; } - // fall through to error + throw makeStringExceptionV(-1,"CDistributedSuperFile::querySubFile(%u) for superfile %s - subfile doesn't exist ", idx, logicalName.get()); } return subfiles.item(idx); }