Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

fix: web3-validator ajv memory leak #5574

Merged
merged 3 commits into from
Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/web3-validator/src/web3_validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import Ajv from 'ajv';
import { blake2b } from 'ethereum-cryptography/blake2b';
import { utf8ToBytes, toHex } from 'ethereum-cryptography/utils';
import { ethAbiToJsonSchema } from './utils';
import { ValidationSchemaInput, Web3ValidationErrorObject, Web3ValidationOptions } from './types';
import { ethKeyword } from './keywords/eth';
Expand Down Expand Up @@ -98,7 +100,11 @@ export class Web3Validator {
]);
}

if (!this._validator.validate(jsonSchema, data)) {
const schemaKey = toHex(blake2b(utf8ToBytes(JSON.stringify(jsonSchema))));
if (!this._validator.getSchema(schemaKey)) {
this._validator.addSchema(jsonSchema, schemaKey);
}
if (!this._validator.validate(schemaKey, data)) {
const errors = this._validator.errors as Web3ValidationErrorObject[];

if (options?.silent) {
Expand Down