summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-01-28 15:02:54 +0000
committerAron Budea <aron.budea@collabora.com>2022-08-11 05:30:51 +0200
commit64bebaacbe9387496cc10d7a6096ee33da2cf68f (patch)
tree3adc2203d5e25e42d74a11781e61731a5d13c1b9
parent5bb7f02cee0382d7c45955bfbdcee73d486c9135 (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/+/129076 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit e95d5d5666505cb05e9660f24f6c7ae039451ef8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129759 (cherry picked from commit bfff5c7dadf9628926fbb5cd0394fcfc4464eb0b)
-rw-r--r--hwpfilter/source/hwpreader.cxx64
1 files changed, 15 insertions, 49 deletions
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 4cfa65356c4b..17cfe7f48ad3 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.get());
mxList->clear();
+ if (emp)
+ {
+ rstartEl("office:binary-data", mxList.get());
+ 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. */