[Libreoffice-commits] core.git: emfio/source vcl/qa
emfio/source/reader/wmfreader.cxx| 470 ++- vcl/qa/cppunit/graphicfilter/data/README | 19 - 2 files changed, 297 insertions(+), 192 deletions(-) New commits: commit 00e02dd832988ec3e7f37569c932ed66e1eb6efd Author: Bartosz Kosiorek AuthorDate: Tue Jun 20 16:45:38 2023 +0200 Commit: Bartosz Kosiorek CommitDate: Sat Oct 28 11:06:40 2023 +0200 tdf#155887 Add individual WMF records validation In previous implementation, there was no proper validation of the records, by it's size. This commit adds validation of the WMF records. It would allow to interrupt reading, if wrong record found and play only records until it it correct. It will allow to mimic the behaviour of MS Office: If the wrong record is detected, the image is displayed till the wrong record. Currently in LibreOffice, if wrong record is found whole read is interrupted. Change-Id: I0c82deabcec7a416ca44540e693822f1986437eb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153351 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx index cfb15cd31eac..fd954e960c49 100644 --- a/emfio/source/reader/wmfreader.cxx +++ b/emfio/source/reader/wmfreader.cxx @@ -286,54 +286,71 @@ namespace emfio void WmfReader::ReadRecordParams( sal_uInt32 nRecordSize, sal_uInt16 nFunc ) { +bool bRecordOk = true; SAL_INFO("emfio", "\t" << record_type_name(nFunc)); -switch( nFunc ) +switch(nFunc) { case W_META_SETBKCOLOR: { -SetBkColor( ReadColor() ); +if (nRecordSize != 5) +bRecordOk = false; +SetBkColor(ReadColor()); } break; case W_META_SETBKMODE: { +// It could have Reserved values. Both 4 and 5 sizes are allowed +if ((nRecordSize != 4) && (nRecordSize != 5)) +bRecordOk = false; sal_uInt16 nDat = 0; mpInputStream->ReadUInt16( nDat ); SetBkMode( static_cast(nDat) ); } break; -// !!! case W_META_SETMAPMODE: { -sal_Int16 nMapMode = 0; -mpInputStream->ReadInt16( nMapMode ); -SetMapMode( static_cast(nMapMode) ); +if (nRecordSize != 4) +bRecordOk = false; +sal_uInt16 nMapMode = 0; +mpInputStream->ReadUInt16(nMapMode); +SetMapMode(static_cast(nMapMode)); } break; case W_META_SETROP2: { +// It could have Reserved values. Both 4 and 5 sizes are allowed +if ((nRecordSize != 4) && (nRecordSize != 5)) +bRecordOk = false; sal_uInt16 nROP2 = 0; -mpInputStream->ReadUInt16( nROP2 ); -SetRasterOp( static_cast(nROP2) ); +mpInputStream->ReadUInt16(nROP2); +SetRasterOp(static_cast(nROP2)); +mpInputStream->SeekRel(2); // reserved data } break; case W_META_SETTEXTCOLOR: { +if (nRecordSize != 5) +bRecordOk = false; SetTextColor( ReadColor() ); } break; case W_META_SETWINDOWORG: { +if (nRecordSize != 5) +bRecordOk = false; SetWinOrg( ReadYX() ); } break; case W_META_SETWINDOWEXT: { +if (nRecordSize != 5) +bRecordOk = false; short nWidth = 0, nHeight = 0; mpInputStream->ReadInt16( nHeight ).ReadInt16( nWidth ); SetWinExt( Size( nWidth, nHeight ) ); @@ -342,6 +359,8 @@ namespace emfio case W_META_OFFSETWINDOWORG: { +if (nRecordSize != 5) +bRecordOk = false; short nXAdd = 0, nYAdd = 0; mpInputStream->ReadInt16( nYAdd ).ReadInt16( nXAdd ); SetWinOrgOffset( nXAdd, nYAdd ); @@ -350,6 +369,8 @@ namespace emfio case W_META_SCALEWINDOWEXT: { +if (nRecordSize != 7) +bRecordOk = false; short nXNum = 0, nXDenom = 0, nYNum = 0, nYDenom = 0; mpInputStream->ReadInt16( nYDenom ).ReadInt16( nYNum ).ReadInt16( nXDenom ).ReadInt16( nXNum ); if (!nYDenom || !nXDenom) @@ -363,10 +384,16 @@ namespace emfio case W_META_SETVIEWPORTORG: case W_META_SETVIEWPORTEXT: +{ +if (nRecordSize
[Libreoffice-commits] core.git: emfio/source vcl/qa
emfio/source/reader/wmfreader.cxx |2 +- vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35150-1.wmf |binary 2 files changed, 1 insertion(+), 1 deletion(-) New commits: commit 79260c7cd80107f223e0f9bcf4bd91ae40566cbe Author: Caolán McNamara AuthorDate: Fri Jun 11 10:23:29 2021 +0100 Commit: Caolán McNamara CommitDate: Fri Jun 11 12:47:38 2021 +0200 ofz#35150 crash in Bitmap::Crop from wmf load which is a problem since... commit 33d2cf7008de79106b5da4bba0241aa14d81d88f Date: Sat Jun 5 19:30:46 2021 +0200 WMF Change the sign of read fields in BITBLT and DIB records Change-Id: Iea1261a52866d691435f0612f672636009c00355 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117039 Tested-by: Jenkins Reviewed-by: Caolán McNamara diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx index f506de102bfe..93908503d9bf 100644 --- a/emfio/source/reader/wmfreader.cxx +++ b/emfio/source/reader/wmfreader.cxx @@ -832,7 +832,7 @@ namespace emfio break; } const vcl::PixelFormat ePixelFormat = vcl::bitDepthToPixelFormat( nBitCount ); -bool bOk = nWidth && nHeight && nBytesPerScan > 0 && nPlanes == 1 && ePixelFormat != vcl::PixelFormat::INVALID; +bool bOk = nWidth > 0 && nHeight > 0 && nBytesPerScan > 0 && nPlanes == 1 && ePixelFormat != vcl::PixelFormat::INVALID; if (bOk) { // must be enough data to fulfil the request diff --git a/vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35150-1.wmf b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35150-1.wmf new file mode 100644 index ..2d156198194c Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35150-1.wmf differ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: emfio/source vcl/qa
emfio/source/reader/wmfreader.cxx |2 +- vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35149-1.wmf |binary 2 files changed, 1 insertion(+), 1 deletion(-) New commits: commit 54344deb66b2aca47bfcc9cadcbc0262fc4c138b Author: Caolán McNamara AuthorDate: Fri Jun 11 10:12:50 2021 +0100 Commit: Caolán McNamara CommitDate: Fri Jun 11 12:47:18 2021 +0200 ofz#35149 crash in vcl::bitmap::CreateFromData from wmf load which has started since... commit 01ded1e6d362dbcd7148334c6965d6ad00981d4a Date: Tue Jun 8 23:07:28 2021 +0200 WMF tdf#55058 tdf#142722 Add implementation of BitBlt and StretchBlt Change-Id: I5bbde55dbd9e239c05544ac4a21e2758770245d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117038 Tested-by: Jenkins Reviewed-by: Caolán McNamara diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx index 38f6252afa59..f506de102bfe 100644 --- a/emfio/source/reader/wmfreader.cxx +++ b/emfio/source/reader/wmfreader.cxx @@ -841,7 +841,7 @@ namespace emfio if (bOk) { // scanline must be large enough to provide all pixels -bOk = nBytesPerScan >= nWidth / 8; +bOk = nBytesPerScan >= nWidth * nBitCount / 8; } if (bOk) { diff --git a/vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35149-1.wmf b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35149-1.wmf new file mode 100644 index ..f91e3a9fb056 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/ofz35149-1.wmf differ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] core.git: emfio/source vcl/qa
emfio/source/reader/wmfreader.cxx | 23 ++-- vcl/qa/cppunit/graphicfilter/data/wmf/fail/exttextout-2.wmf |binary 2 files changed, 12 insertions(+), 11 deletions(-) New commits: commit 7cfb3d2873f0e281e20ccd5ff004746eb4bd4ce5 Author: Caolán McNamaraDate: Tue Mar 6 09:24:04 2018 + ofz: timeout Change-Id: I7cdd39f51943bd97e0e0931f44d3338a23044ab0 Reviewed-on: https://gerrit.libreoffice.org/50802 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx index e82d756f28b2..eafff0378716 100644 --- a/emfio/source/reader/wmfreader.cxx +++ b/emfio/source/reader/wmfreader.cxx @@ -1387,7 +1387,7 @@ namespace emfio if( mnEndPos - mnStartPos ) { - bool bEMFAvailable = false; +bool bEMFAvailable = false; while( true ) { mnCurrentAction++; @@ -1404,6 +1404,15 @@ namespace emfio break; } + +const sal_uInt32 nAvailableBytes = mnEndPos - nPos; +const sal_uInt32 nMaxPossibleRecordSize = nAvailableBytes/2; +if (mnRecSize > nMaxPossibleRecordSize) +{ +mpInputStream->SetError(SVSTREAM_FILEFORMAT_ERROR); +break; +} + if ( !bEMFAvailable ) { if( !maBmpSaveList.empty() @@ -1448,16 +1457,8 @@ namespace emfio } } -const sal_uInt32 nAvailableBytes = mnEndPos - nPos; -const sal_uInt32 nMaxPossibleRecordSize = nAvailableBytes/2; - -if (mnRecSize <= nMaxPossibleRecordSize) -{ -nPos += mnRecSize * 2; -mpInputStream->Seek(nPos); -} -else -mpInputStream->SetError( SVSTREAM_FILEFORMAT_ERROR ); +nPos += mnRecSize * 2; +mpInputStream->Seek(nPos); } } else diff --git a/vcl/qa/cppunit/graphicfilter/data/wmf/fail/exttextout-2.wmf b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/exttextout-2.wmf new file mode 100644 index ..02c72ad88fa8 Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/exttextout-2.wmf differ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits