@@ -371,19 +371,28 @@ function captureSegment (state, start, end, checkJson) {
371371 }
372372}
373373
374+ function chargeMergeWork ( state ) {
375+ state . totalMergeKeys ++
376+
377+ if ( state . maxTotalMergeKeys !== - 1 && state . totalMergeKeys > state . maxTotalMergeKeys ) {
378+ throwError ( state , 'merge keys exceeded maxTotalMergeKeys (' + state . maxTotalMergeKeys + ')' )
379+ }
380+ }
381+
374382function mergeMappings ( state , destination , source , overridableKeys ) {
375383 if ( ! common . isObject ( source ) ) {
376384 throwError ( state , 'cannot merge mappings; the provided source object is unacceptable' )
377385 }
378386
387+ // Count the source mapping itself to bound sequences of empty mappings.
388+ chargeMergeWork ( state )
389+
379390 const sourceKeys = Object . keys ( source )
380391
381392 for ( let index = 0 , quantity = sourceKeys . length ; index < quantity ; index += 1 ) {
382393 const key = sourceKeys [ index ]
383394
384- if ( state . maxTotalMergeKeys !== - 1 && ++ state . totalMergeKeys > state . maxTotalMergeKeys ) {
385- throwError ( state , 'merge keys exceeded maxTotalMergeKeys (' + state . maxTotalMergeKeys + ')' )
386- }
395+ chargeMergeWork ( state )
387396
388397 if ( ! _hasOwnProperty . call ( destination , key ) ) {
389398 setProperty ( destination , key , source [ key ] )
@@ -426,6 +435,10 @@ function storeMappingPair (state, _result, overridableKeys, keyTag, keyNode, val
426435
427436 if ( keyTag === 'tag:yaml.org,2002:merge' ) {
428437 if ( Array . isArray ( valueNode ) ) {
438+ if ( valueNode . length > 100 ) {
439+ throwError ( state , 'abnormal merge sequence size' )
440+ }
441+
429442 for ( let index = 0 , quantity = valueNode . length ; index < quantity ; index += 1 ) {
430443 mergeMappings ( state , _result , valueNode [ index ] , overridableKeys )
431444 }
0 commit comments