diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-01-28 15:02:54 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-01-29 14:31:01 +0100 |
commit | 8c5619b0272a67530760573993814fe7968a6c97 (patch) | |
tree | ad8bb76036ef587aa5795fb500634e636c436f2f | |
parent | 0e0175629fd0c6a99bb286f155e7a4855b8473d6 (diff) |
avoid dangling tmp files in hwp import
if there is embedded data use office-binary-data to transport it
instead of a temp file
https: //issues.oasis-open.org/browse/OFFICE-3933
Change-Id: Ia1cebf0770c99210df09f03dbb507451d9cf7764
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129114
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | hwpfilter/source/hwpreader.cxx | 64 |
1 files changed, 15 insertions, 49 deletions
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx index e26cbb26143a..d402e4250e92 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -514,62 +514,28 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo ) if( prop->flag >> 18 & 0x01 ) { padd( "draw:name", sXML_CDATA, ascii(Int2Str(hdo->index, "fillimage%d", buf))); - if( !prop->pictype ) + + EmPicture *emp = nullptr; + if (prop->pictype && strlen(prop->szPatternFile) > 3) + emp = hwpfile.GetEmPictureByName(prop->szPatternFile); + if (!emp) { padd( "xlink:href", sXML_CDATA, fromHcharStringToOUString(hstr2ucsstr(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str()))); + padd( "xlink:type", sXML_CDATA, "simple"); + padd( "xlink:show", sXML_CDATA, "embed"); + padd( "xlink:actuate", sXML_CDATA, "onLoad"); } - else - { - EmPicture *emp = nullptr; - if ( strlen( prop->szPatternFile ) > 3) - emp = hwpfile.GetEmPictureByName(prop->szPatternFile); - if( emp ) - { - char filename[128+17+9]; - char dirname[128]; - int fd; -#ifdef _WIN32 - GetTempPathA(sizeof(dirname), dirname); - sprintf(filename, "%s%s",dirname, emp->name); - if( (fd = open( filename , _O_CREAT | _O_WRONLY | _O_BINARY , 0666)) >= 0 ) -#else - strcpy(dirname, "/tmp/"); - sprintf(filename, "%s%s", dirname, emp->name); - if( (fd = open( filename , O_CREAT | O_WRONLY , 0666)) >= 0 ) -#endif - { - size_t nWritten = write(fd, emp->data.get(), emp->size); - OSL_VERIFY(nWritten == emp->size); - close(fd); - } -#ifdef _WIN32 - int j; - for(j = 0 ; j < static_cast<int>(strlen( dirname )) ; j++) - { - if( dirname[j] == '\\' ) buf[j] = '/'; - else buf[j] = dirname[j]; - } - buf[j] = '\0'; - sprintf(filename, "file:///%s%s",buf, emp->name ); -#else - sprintf(filename, "file://%s%s",dirname, emp->name ); -#endif - padd( "xlink:href", sXML_CDATA, ascii(filename)); - } - else - { - padd( "xlink:href", sXML_CDATA, - fromHcharStringToOUString(hstr2ucsstr(kstr2hstr( reinterpret_cast<uchar const *>(urltounix(prop->szPatternFile).c_str())).c_str()))); - } - - } - padd( "xlink:type", sXML_CDATA, "simple"); - padd( "xlink:show", sXML_CDATA, "embed"); - padd( "xlink:actuate", sXML_CDATA, "onLoad"); rstartEl( "draw:fill-image", mxList); mxList->clear(); + if (emp) + { + rstartEl("office:binary-data", mxList); + std::shared_ptr<char> pStr(base64_encode_string(emp->data.get(), emp->size), Free<char>()); + rchars(ascii(pStr.get())); + rendEl("office:binary-data"); + } rendEl( "draw:fill-image"); } /* If there is a gradient, when a bitmap file is present, this is the first. */ |