DescriptionFix the open file dialog on Windows
Currently even if a valid file is selected the OpenFileDialog is likely
to return an emtpy FilePath, depending on what is in memory after the
sole string returned by the Windows OFD. The code as written assumes
the Windows OFD will always return a null-terminated list of
null-terminated strings when returning successfully from the call to
the OFD. However if you check the MSDN documentation at:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839(v=vs.85).aspx
You will find this is not the case, and the return value depends on the
presence of OFN_ALLOWMULTISELECT in the Flags argument. If that value
is not set, which it is not in the case of single-file selection, then
there is only a single string in |openfilename_.lpstrFile|, and the
code within OpenFileName::GetResult() blows past that single NULL and
into unitialized memory, which ::GetSingleResult then assumes means
an invalid return filename and returns the empty FilePath.
This CL repairs that situation so that GetSingleResult now DCHECKS
that the OFN_ALLOWMULTISELECT is not there and returns the string
directly, and ::GetResult() asserts that the flag is present and
continues to do its multi-value parsing that it was doing before.
BUG=418760
TEST=Launch Chrome, hit CTRL+O to open a file, chose a valid test html
file, observe that the browser doesn't crash and successfully opens that
file.
Committed: https://crrev.com/702fdfed602988a1d404ae4c862c252d40209995
Cr-Commit-Position: refs/heads/master@{#297489}
Patch Set 1 #
Total comments: 4
Patch Set 2 : fixing unit tests and feedback #
Messages
Total messages: 12 (3 generated)
|