Skip to content

Instantly share code, notes, and snippets.

@JobLeonard
Last active April 30, 2024 15:35
Show Gist options
  • Save JobLeonard/79f4124775cc26202216b8e20da8b9f6 to your computer and use it in GitHub Desktop.
Save JobLeonard/79f4124775cc26202216b8e20da8b9f6 to your computer and use it in GitHub Desktop.
TypedArray OOB write access
{"title":"TypedArray OOB write access","initialization":"// runs once\n\nconst size = 10000;\n\nconst ta1 = new Float32Array(size);\nconst ta2 = new Float32Array(size);\nconst ta3 = new Float32Array(size);\n\nfunction respectsBounds(arr) {\n const r = Math.random;\n for (let i = 0; i < arr.length; i++) {\n arr[i] = r();\n }\n return arr;\n};\n\nfunction respectsBounds2(arr) {\n const r = Math.random;\n for (let i = 0; i < size; i++) {\n arr[i] = r();\n }\n return arr;\n};\n\nfunction outOfBounds(arr) {\n const r = Math.random;\n const s2 = size + 1000;\n for (let i = 1000; i < s2; i++) {\n arr[i] = r();\n }\n return arr;\n};","setup":"// runs before each test\nconst r = Math.random;\nfor (let i = 0; i < ta1.length; i++) {\n ta1[i] = ta2[i] = ta3[i] = r();\n}","tests":[{"name":"respectsBounds","code":"const v = respectsBounds(ta1);","results":{"aborted":false,"count":976,"cycles":2,"hz":9087.523277467413,"stats":{"moe":5.7089443112675e-7,"rme":0.5188016431840857,"sem":2.912726689422194e-7,"deviation":0.0000020596087938334764,"mean":0.00011004098360655737,"variance":4.241988383636188e-12,"numSamples":50},"times":{"cycle":0.1074,"elapsed":5.853,"period":0.00011004098360655737,"timeStamp":1714490537255}},"platforms":{"Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0":{"aborted":false,"count":3054,"cycles":4,"hz":36833.355085268886,"stats":{"moe":4.984411008109476e-7,"rme":1.835925805526194,"sem":2.543066840872182e-7,"deviation":0.0000019533667051311013,"mean":0.00002714930523393834,"variance":3.815641484714734e-12,"numSamples":59},"times":{"cycle":0.08291397818444769,"elapsed":5.923,"period":0.00002714930523393834,"timeStamp":1714490311769}},"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36":{"aborted":false,"count":976,"cycles":2,"hz":9087.523277467413,"stats":{"moe":5.7089443112675e-7,"rme":0.5188016431840857,"sem":2.912726689422194e-7,"deviation":0.0000020596087938334764,"mean":0.00011004098360655737,"variance":4.241988383636188e-12,"numSamples":50},"times":{"cycle":0.1074,"elapsed":5.853,"period":0.00011004098360655737,"timeStamp":1714490537255}}}},{"name":"respectsBounds2","code":"const v = respectsBounds2(ta2);","results":{"aborted":false,"count":976,"cycles":2,"hz":10496.639139619741,"stats":{"moe":0.0000010481109399502424,"rme":1.100164231494535,"sem":5.347504795664502e-7,"deviation":0.000004001706163901432,"mean":0.00009526858899297425,"variance":1.6013652222206713e-11,"numSamples":56},"times":{"cycle":0.09298214285714286,"elapsed":5.723,"period":0.00009526858899297425,"timeStamp":1714490543114}},"platforms":{"Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0":{"aborted":false,"count":2873,"cycles":3,"hz":36819.32179571032,"stats":{"moe":3.1172845504221285e-7,"rme":1.1477630299078851,"sem":1.5904513012357798e-7,"deviation":0.0000012723610409886238,"mean":0.000027159652900410194,"variance":1.6189026186256543e-12,"numSamples":64},"times":{"cycle":0.07802968278287849,"elapsed":6.012,"period":0.000027159652900410194,"timeStamp":1714490317698}},"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36":{"aborted":false,"count":976,"cycles":2,"hz":10496.639139619741,"stats":{"moe":0.0000010481109399502424,"rme":1.100164231494535,"sem":5.347504795664502e-7,"deviation":0.000004001706163901432,"mean":0.00009526858899297425,"variance":1.6013652222206713e-11,"numSamples":56},"times":{"cycle":0.09298214285714286,"elapsed":5.723,"period":0.00009526858899297425,"timeStamp":1714490543114}}}},{"name":"outOfBounds","code":"const v = outOfBounds(ta3);","results":{"aborted":false,"count":976,"cycles":2,"hz":8635.576036866361,"stats":{"moe":0.0000014143200770088905,"rme":1.2213468565476961,"sem":7.215918760249441e-7,"deviation":0.000004999335166416582,"mean":0.00011580003415300544,"variance":2.499335210616952e-11,"numSamples":48},"times":{"cycle":0.1130208333333333,"elapsed":5.865,"period":0.00011580003415300544,"timeStamp":1714490548843}},"platforms":{"Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0":{"aborted":false,"count":3007,"cycles":4,"hz":38707.102177815905,"stats":{"moe":3.0705029817867324e-7,"rme":1.1885027265330745,"sem":1.5665831539728228e-7,"deviation":0.0000012532665231782582,"mean":0.00002583505206373024,"variance":1.5706769781193197e-12,"numSamples":64},"times":{"cycle":0.07768600155563683,"elapsed":6.119,"period":0.00002583505206373024,"timeStamp":1714490323715}},"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36":{"aborted":false,"count":976,"cycles":2,"hz":8635.576036866361,"stats":{"moe":0.0000014143200770088905,"rme":1.2213468565476961,"sem":7.215918760249441e-7,"deviation":0.000004999335166416582,"mean":0.00011580003415300544,"variance":2.499335210616952e-11,"numSamples":48},"times":{"cycle":0.1130208333333333,"elapsed":5.865,"period":0.00011580003415300544,"timeStamp":1714490548843}}}}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment