Skip to content

Commit 5e2ea00

Browse files
committed
Fix #66322: COMPersistHelper::SaveToFile can save to wrong location
Saving under the given `filename` may also work, but since `::LoadFromFile` uses the `fullpath` we follow suit.
1 parent 13bfa9f commit 5e2ea00

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.3.16
44

5+
- COM:
6+
. Fixed bug #66322 (COMPersistHelper::SaveToFile can save to wrong location).
7+
(cmb)
8+
59
- PCRE:
610
. Fixed bug #79188 (Memory corruption in preg_replace/preg_replace_callback
711
and unicode). (Nikita)

ext/com_dotnet/com_persist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ CPH_METHOD(SaveToFile)
398398
RETURN_FALSE;
399399
}
400400

401-
olefilename = php_com_string_to_olestring(filename, strlen(fullpath), helper->codepage);
401+
olefilename = php_com_string_to_olestring(fullpath, strlen(fullpath), helper->codepage);
402402
efree(fullpath);
403403
}
404404
res = IPersistFile_Save(helper->ipf, olefilename, remember);

ext/com_dotnet/tests/bug66322.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #66322 (COMPersistHelper::SaveToFile can save to wrong location)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6+
try {
7+
new COM('Word.Application');
8+
} catch (com_exception $ex) {
9+
die('skip MS Word not available');
10+
}
11+
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
12+
?>
13+
--FILE--
14+
<?php
15+
$w = new COM('Word.Application');
16+
$doc = $w->Documents->Add();
17+
$ph = new COMPersistHelper($doc);
18+
$filename = __DIR__ . '\\..\\' . basename(__DIR__) . '\\66322.docx';
19+
$ph->SaveToFile($filename);
20+
var_dump(file_exists($filename));
21+
$w->Quit();
22+
?>
23+
--EXPECT--
24+
bool(true)

0 commit comments

Comments
 (0)