Merge pull request from GHSA-9vx6-7xxf-x967

* add tests for the encode reads dirty data issue

* Fix the encode reads dirty data issue

* add changeset

* trigger the issue without assembly

* rename mock

* gas optimization

* Apply suggestions from code review

Co-authored-by: Ernesto García <ernestognw@gmail.com>

* alternative fix: cheaper

* update comment

* fix lint

---------

Co-authored-by: Ernesto García <ernestognw@gmail.com>
This commit is contained in:
Hadrien Croubois
2024-02-29 17:03:32 +01:00
committed by GitHub
parent 8b4b7b8d04
commit 92224533b1
4 changed files with 51 additions and 9 deletions

View File

@ -47,4 +47,13 @@ describe('Strings', function () {
expect(await this.mock.$encodeURL(buffer)).to.equal(expected);
});
});
it('Encode reads beyond the input buffer into dirty memory', async function () {
const mock = await ethers.deployContract('Base64Dirty');
const buffer32 = ethers.id('example');
const buffer31 = buffer32.slice(0, -2);
expect(await mock.encode(buffer31)).to.equal(ethers.encodeBase64(buffer31));
expect(await mock.encode(buffer32)).to.equal(ethers.encodeBase64(buffer32));
});
});