MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / decodeSymbol2

Method decodeSymbol2

Libraries/unrar/model.cpp:490–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488
489
490inline bool RARPPM_CONTEXT::decodeSymbol2(ModelPPM *Model)
491{
492 int count, HiCnt, i=NumStats-Model->NumMasked;
493 RARPPM_SEE2_CONTEXT* psee2c=makeEscFreq2(Model,i);
494 RARPPM_STATE* ps[256], ** pps=ps, * p=U.Stats-1;
495 HiCnt=0;
496 do
497 {
498 do
499 {
500 p++;
501 } while (Model->CharMask[p->Symbol] == Model->EscCount);
502 HiCnt += p->Freq;
503
504 // We do not reuse PPMd coder in unstable state, so we do not really need
505 // this check and added it for extra safety. See CVE-2017-17969 for details.
506 if (pps>=ps+ASIZE(ps))
507 return false;
508
509 *pps++ = p;
510 } while ( --i );
511 Model->Coder.SubRange.scale += HiCnt;
512 count=Model->Coder.GetCurrentCount();
513 if (count>=(int)Model->Coder.SubRange.scale)
514 return(false);
515 p=*(pps=ps);
516 if (count < HiCnt)
517 {
518 HiCnt=0;
519 while ((HiCnt += p->Freq) <= count)
520 {
521 pps++;
522 if (pps>=ps+ASIZE(ps)) // Extra safety check.
523 return false;
524 p=*pps;
525 }
526 Model->Coder.SubRange.LowCount = (Model->Coder.SubRange.HighCount=HiCnt)-p->Freq;
527 psee2c->update();
528 update2(Model,p);
529 }
530 else
531 {
532 Model->Coder.SubRange.LowCount=HiCnt;
533 Model->Coder.SubRange.HighCount=Model->Coder.SubRange.scale;
534 i=NumStats-Model->NumMasked;
535 pps--;
536 do
537 {
538 pps++;
539 if (pps>=ps+ASIZE(ps)) // Extra safety check.
540 return false;
541 Model->CharMask[(*pps)->Symbol]=Model->EscCount;
542 } while ( --i );
543 psee2c->Summ += Model->Coder.SubRange.scale;
544 Model->NumMasked = NumStats;
545 }
546 return true;
547}

Callers 1

DecodeCharMethod · 0.80

Calls 2

GetCurrentCountMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected