Repository navigation
reject out-of-range sourceIndex in source map parser - #2253
Medios-lgtm wants to merge 1 commit into
Conversation
Signed-off-by: sabith saheb <admin@medios.digiscrypt.com>
|
Hi @Medios-lgtm! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
SourceMapParserbuilds each segment'ssourceIndexby accumulating a delta-encoded VLQ value, but never checks it against the number of entries in the map'ssourcesarray. The comment inSourceMap::getLocationForAddressFIndexclaimsparseSegment()validated this, but nothing did.SourceMap::getLocationForAddresspasses the value togetSourceFullPath, which indexessources_directly behind only a debug-onlyassert.A source map whose mapping segment names an out-of-range (or negative)
sourceIndextherefore readssources_out of bounds once a location is queried, for example whenSourceMapTranslator::translatemaps a diagnostic back through an attached input source map. In a release build theassertis compiled out and the wildstd::stringbecomes aStringRefused as a file name.This validates
sourceIndexwhile parsing the mappings and rejects the map if any segment is out of range, which is where the stale comment already expected the check to live.nameIndexis not validated because it indexes no array at query time (it is only re-emitted by the generator).The
unittests/SourceMapdirectory was never wired intounittests/CMakeLists.txt, so its tests did not build or run; this adds theadd_subdirectoryline and a regression test alongside it.Test Plan
AgqjGAAdecodes tosourceIndex100000 andADAAto -1, against a map with a single source. Before the change, compiling the standalone parser with-DNDEBUG -fsanitize=addressand callinggetLocationForAddress(1, 1)reports:After the change both maps are rejected by the parser and a valid map still resolves its source. New test
SourceMap.OutOfRangeSourceIndexfails before the fix and passes after; the fullHermesSourceMapTestssuite (14 tests) passes, and thehermestarget builds clean under the ASan+Debug configuration.