fix(webdriver): handle large images on screenshot (fix for 14489 bug)#14491
fix(webdriver): handle large images on screenshot (fix for 14489 bug)#14491christian-bromann merged 2 commits intowebdriverio:mainfrom
Conversation
|
Thank you for the awesome work 👏 Could you add some unit tests for these changes so we know it is and keeps working as intended in the future? 😉 |
christian-bromann
left a comment
There was a problem hiding this comment.
One comment, also could we add a unit test for this?
88bd5b1 to
a1e2bd7
Compare
christian-bromann
left a comment
There was a problem hiding this comment.
One comment, otherwise LGTM 👍
eslint-plugin-wdio
@wdio/allure-reporter
@wdio/browser-runner
@wdio/appium-service
@wdio/browserstack-service
@wdio/cli
@wdio/concise-reporter
@wdio/config
@wdio/cucumber-framework
@wdio/dot-reporter
@wdio/firefox-profile-service
@wdio/globals
@wdio/jasmine-framework
@wdio/json-reporter
@wdio/junit-reporter
@wdio/lighthouse-service
@wdio/local-runner
@wdio/logger
@wdio/mocha-framework
@wdio/protocols
@wdio/repl
@wdio/reporter
@wdio/runner
@wdio/sauce-service
@wdio/shared-store-service
@wdio/smoke-test-cjs-service
@wdio/smoke-test-reporter
@wdio/smoke-test-service
@wdio/spec-reporter
@wdio/static-server-service
@wdio/sumologic-reporter
@wdio/testingbot-service
@wdio/types
@wdio/utils
@wdio/webdriver-mock-service
webdriver
webdriverio
commit: |
|
Hey nikoslytras 👋 Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution. We've sent you an email with further instructions on how to claim your expenses from our development fund. We are looking forward to more contributions from you in the future 🙌 Have a nice day, |
|
I used to see issue with PNG image. |
Related issue
Closes #14489
Proposed changes
Problem Recap
Validating extremely large Base64-encoded strings using a regular expression directly can lead to performance issues or runtime errors such as RangeError: Maximum call stack size exceeded. This typically occurs with very large payloads, such as image data encoded in Base64 (e.g., screenshots with 4+ million characters).
Updated Approach
To address this, we implemented a scalable validation strategy in the isBase64Safe function. The key change is the use of adaptive chunking for large inputs to avoid overwhelming the regex engine.
How It Works:
For small strings (length ≤ BASE_64_SAFE_STRING_TO_PROCESS_LENGTH), the regular expression is applied directly to the entire string.
For larger strings:
The string’s total length is used to determine the number of digits (i.e., its order of magnitude).
The input is split into fixed-size chunks, where each chunk’s size is calculated as:
Math.floor(length / digitCount / 4) * 4
(ensuring chunk lengths are divisible by 4 for valid Base64 structure).
Each chunk is tested individually against the BASE_64_REGEX.
If any chunk fails validation, the entire string is considered invalid.
If all chunks pass, the string is considered valid.
Benefits
Scalable: Handles very large Base64 strings without risking stack overflows or regex engine limitations.
Efficient: Reduces validation cost by applying regex in smaller, manageable chunks.
Safe: Ensures accurate Base64 validation while preserving application stability, even for very large inputs.
This enhancement allows the system to safely validate large, complex Base64 strings—such as those generated from high-resolution screenshots—without compromising performance or reliability.
Types of changes
Checklist
Backport Request
//: # (The current
mainbranch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against thev8branch.)v9and doesn't need to be back-ported#XXXXXFurther comments
Reviewers: @webdriverio/project-committers