From e3f4a646aef5094c660e10c18eecce8f5bbe0be6 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 | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/dali/base/dadfs.cpp b/dali/base/dadfs.cpp index 1ff1c0fee5d..51100ed8a6f 100644 --- a/dali/base/dadfs.cpp +++ b/dali/base/dadfs.cpp @@ -6271,22 +6271,27 @@ class CDistributedSuperFile: public CDistributedFileBase virtual IDistributedFile &querySubFile(unsigned idx,bool sub) override { CriticalBlock block (sect); - if (sub) { - ForEachItemIn(i,subfiles) { + if (sub) + { + unsigned subfilen = idx; + ForEachItemIn(i,subfiles) + { IDistributedFile &f=subfiles.item(i); IDistributedSuperFile *super = f.querySuperFile(); - if (super) { + 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); + else + return subfiles.item(idx); } virtual IDistributedFile *querySubFileNamed(const char *name, bool sub) override