Browse Source

Merge pull request #15762 from ghalliday/issue27157

HPCC-27157 Avoid processing dependencies from .tgz files

Reviewed-By: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 3 years ago
parent
commit
823291bc79
3 changed files with 23 additions and 0 deletions
  1. 7 0
      ecl/hql/hqlcollect.cpp
  2. 15 0
      ecl/hql/hqlrepository.cpp
  3. 1 0
      ecl/hql/hqlrepository.hpp

+ 7 - 0
ecl/hql/hqlcollect.cpp

@@ -25,6 +25,7 @@
 #include "hqlexpr.hpp"
 #include "hqlerrors.hpp"
 
+#include "hqlrepository.hpp"        // MORE: Temporary until HPCC-27173 is implemented
 #ifdef _USE_ZLIB
 #include "zcrypt.hpp"
 #endif
@@ -568,12 +569,18 @@ void FileSystemDirectory::processDependencies(IPropertyTree * dependTree, const
             name = decodedName;
         }
 
+        if (!isValidIdentifier(name))
+            continue;
+
         //Ignore the entry if it has already been defined (node_modules has precedence over package-lock.json over package.json)
         IIdAtom * id = createIdAtom(name);
         if (find(id))
             continue;
 
         const char * url = isPackageLock ? cur.queryProp("resolved") : cur.queryProp(nullptr);
+        if (!canReadPackageFrom(url))
+            continue;
+
         PackageDependency * depend = new PackageDependency(id, url, onlyAllowSHA);
         contents.append(*depend);
     }

+ 15 - 0
ecl/hql/hqlrepository.cpp

@@ -107,6 +107,21 @@ static bool splitRepoVersion(StringBuffer & repoUrn, StringBuffer & repo, String
 }
 
 
+//A (very) temporary solution - to prevent other dependencies from node projects from causing problems
+//the correct fix HPCC-27173, to delay processing the package until actually used.
+bool canReadPackageFrom(const char * urn)
+{
+    if (queryExtractFilename(urn))
+        return true;
+    if (looksLikeGitPackage(urn))
+        return true;
+    if (!isalnum(*urn))
+        return false;
+    if (endsWith(urn, ".tgz"))
+        return false;
+    return true;
+}
+
 //-------------------------------------------------------------------------------------------------------------------
 
 static void extractRootScopes(HqlScopeArray & rootScopes, IHqlScope * scope, HqlLookupContext & ctx)

+ 1 - 0
ecl/hql/hqlrepository.hpp

@@ -101,5 +101,6 @@ extern HQL_API void importRootModulesToScope(IHqlScope * scope, HqlLookupContext
 extern HQL_API IHqlScope * getResolveDottedScope(const char * modname, unsigned lookupFlags, HqlLookupContext & ctx);
 extern HQL_API IHqlExpression * getResolveAttributeFullPath(const char * attrname, unsigned lookupFlags, HqlLookupContext & ctx, IEclPackage * optPackage);
 extern HQL_API bool looksLikeGitPackage(const char * urn);
+extern HQL_API bool canReadPackageFrom(const char * urn);
 
 #endif