From 475f29c89688f8beb04495c86d8eb540e8c7cc00 Mon Sep 17 00:00:00 2001 From: translatenix <119817707+translatenix@users.noreply.github.com> Date: Tue, 15 Oct 2024 22:20:25 -0700 Subject: [PATCH] Set lower limit for glob pattern resolution in test mode (#693) Motivation: Speed up the test that verifies enforcement of the limit for glob pattern resolution (invalidGlobImport6.pkl). Changes: - Set a lower limit if test mode is enabled. - Change static field to static method to prevent compile-time evaluation by native-image. --- .../main/java/org/pkl/core/util/GlobResolver.java | 13 ++++++++++--- .../src/main/java/org/pkl/core/util/IoUtils.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java b/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java index 3d432a61..700586ae 100644 --- a/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java +++ b/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java @@ -79,9 +79,16 @@ public final class GlobResolver { * a complex glob pattern can starve CPU/memory on a host. * *
Glob limit value taken from https://github.com/openbsd/src/commit/46df4fe576b7 + * href="https://github.com/openbsd/src/commit/46df4fe576b7">https://github.com/openbsd/src/commit/46df4fe576b7. + * + *
If test mode is enabled, a smaller value is used. This greatly speeds up the test that + * verifies enforcement of the limit (invalidGlobImport6.pkl). + * + *
Not a static field to prevent compile-time evaluation by native-image.
*/
- private static final int MAX_LIST_ELEMENTS = 16384;
+ private static int maxListElements() {
+ return IoUtils.isTestMode() ? 512 : 16384;
+ }
private static final Map