From 640c110acd785df2385e90d70c3c34c6ddb9d1e9 Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Wed, 22 Jan 2020 19:34:42 -0500 Subject: [PATCH] Make DreamStation settings size checks less picky. They'll no longer refuse to load the session, and instead they'll flag any small settings slices as unexpected data. --- oscar/SleepLib/loader_plugins/prs1_loader.cpp | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/oscar/SleepLib/loader_plugins/prs1_loader.cpp b/oscar/SleepLib/loader_plugins/prs1_loader.cpp index d1ebb968..e2a29612 100644 --- a/oscar/SleepLib/loader_plugins/prs1_loader.cpp +++ b/oscar/SleepLib/loader_plugins/prs1_loader.cpp @@ -5367,9 +5367,12 @@ bool PRS1DataChunk::ParseSummaryF3V6(void) if (code < ncodes) { // make sure the handlers below don't go past the end of the buffer if (size < minimum_sizes[code]) { + UNEXPECTED_VALUE(size, minimum_sizes[code]); qWarning() << this->sessionid << "slice" << code << "too small" << size << "<" << minimum_sizes[code]; - ok = false; - break; + if (code != 1) { // Settings are variable-length, so shorter settings slices aren't fatal. + ok = false; + break; + } } } // else if it's past ncodes, we'll log its information below (rather than handle it) if (pos + size > chunk_size) { @@ -6192,9 +6195,12 @@ bool PRS1DataChunk::ParseComplianceF0V6(void) } size = this->hblock[code]; if (size < expected_sizes[code]) { + UNEXPECTED_VALUE(size, expected_sizes[code]); qWarning() << this->sessionid << "slice" << code << "too small" << size << "<" << expected_sizes[code]; - ok = false; - break; + if (code != 1) { // Settings are variable-length, so shorter settings slices aren't fatal. + ok = false; + break; + } } if (pos + size > chunk_size) { qWarning() << this->sessionid << "slice" << code << "@" << pos << "longer than remaining chunk"; @@ -6756,9 +6762,12 @@ bool PRS1DataChunk::ParseSummaryF0V6(void) if (code < ncodes) { // make sure the handlers below don't go past the end of the buffer if (size < minimum_sizes[code]) { + UNEXPECTED_VALUE(size, minimum_sizes[code]); qWarning() << this->sessionid << "slice" << code << "too small" << size << "<" << minimum_sizes[code]; - ok = false; - break; + if (code != 1) { // Settings are variable-length, so shorter settings slices aren't fatal. + ok = false; + break; + } } } // else if it's past ncodes, we'll log its information below (rather than handle it) if (pos + size > chunk_size) { @@ -6948,9 +6957,12 @@ bool PRS1DataChunk::ParseSummaryF5V3(void) if (code < ncodes) { // make sure the handlers below don't go past the end of the buffer if (size < minimum_sizes[code]) { + UNEXPECTED_VALUE(size, minimum_sizes[code]); qWarning() << this->sessionid << "slice" << code << "too small" << size << "<" << minimum_sizes[code]; - ok = false; - break; + if (code != 1) { // Settings are variable-length, so shorter settings slices aren't fatal. + ok = false; + break; + } } } // else if it's past ncodes, we'll log its information below (rather than handle it) if (pos + size > chunk_size) {