Menu

#316 Crash when using TFileName with longer names than MAX_PATH

unspecified
open
nobody
None
1
2015-05-07
2015-05-07
Floele
No

Consider the following code:

OWL::TFileName TestFileName("C:\ProgramData\XYZ\1DDFD44E-99DF-4F3D-9A6F-25562F698C0B\Sammelmappen\Projekt\1505102\fsa djlfjasdklfjklaösdjfjkldhsajgkhsdajlkfhdjkghfdjkghfdjk ghkdsfjhgkdjfhgkdjfhg fjsdfh sajkdhfjksadhfjksdhafjkhdasjkfdfgsdjkfhsadkjfhsakdjfhsk jfksdahfjksdhfkjsdahfkjshfkasjdhfskdjfhsakjdfhskdjhfskjdfhsdlakfhaskjdfhskajdhf.TXT");

owl_string sFilename  = TestFileName.GetFullFileNameNoExt();
owl_string sExtension = TestFileName.GetParts(OWL::TFileName::Ext);

It will crash with an access violation exception. I suspect the reason for this being FormCanonicalName where GetFullPathName is called with an insufficiently large buffer, so that the result buffer is not filled at all and FullCanonicalName contains garbage after that. It should probably use the return value of GetFullPathName to provide a larger buffer.

I know it sounds silly operating with files longer than MAX_PATH, but you can really create such files using the Windows UI (create network drive for a certain folder, so that the path is shortened and then you can enter long file names). So whatever application happens to stumble upon such files should not crash.

Discussion


Log in to post a comment.