{"id":1948,"date":"2017-02-03T02:15:59","date_gmt":"2017-02-03T01:15:59","guid":{"rendered":"http:\/\/eskerahn.dk\/?p=1948"},"modified":"2018-10-17T17:53:46","modified_gmt":"2018-10-17T15:53:46","slug":"android-vs-wpd-bug","status":"publish","type":"post","link":"https:\/\/eskerahn.dk\/?p=1948","title":{"rendered":"Android vs WPD bug. Wrong filesizes reported"},"content":{"rendered":"<p>I stumbled upon a strange bug in what Android can report to e.g. Windows trough the MTP\/WPD interface.<\/p>\n<p><a href=\"https:\/\/eskerahn.dk\/?p=1948\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1950\" src=\"https:\/\/eskerahn.dk\/wp-content\/uploads\/2017\/02\/connect-android-phone-to-pc.jpg\" alt=\"\" width=\"749\" height=\"259\" srcset=\"https:\/\/eskerahn.dk\/wp-content\/uploads\/2017\/02\/connect-android-phone-to-pc.jpg 749w, https:\/\/eskerahn.dk\/wp-content\/uploads\/2017\/02\/connect-android-phone-to-pc-150x52.jpg 150w, https:\/\/eskerahn.dk\/wp-content\/uploads\/2017\/02\/connect-android-phone-to-pc-300x104.jpg 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/a><\/p>\n<p>Under some circumstances it reports a VERY wrong file size, but if you by WPD open a stream and copy the file until it sends no more bytes, it returns the correct full content.<\/p>\n<p><!--more--><\/p>\n<p>I had inadvertently triggered the bug by manually moving the DCIM folder to a SD card, and then regretted and moved it back, both with &#8220;Astro&#8221; on a BB Priv on 6.0.1.<\/p>\n<p>After this about half the files in the <em>Camera<\/em> sub-dir no longer reported the correct size. e.g a 7MB file might report as 1.5MB. There were no clear logic to the error. Not any obvious factor or any difference or bit-pattern that indicated what had happened. It wasn&#8217;t neither especially new or old ones, or any clear pattern. Just about 60% of the files. (And only files older than when I moved the folder a few weeks ago)<\/p>\n<p>I tried on a different pc, to attempt to see if it was a Windows bug, and also reset the phablet. No difference, and same incorrect numbers.<\/p>\n<p>I modified the <a href=\"https:\/\/eskerahn.dk\/?p=1668\" target=\"_blank\" rel=\"noopener\">PortableDevicesIncrementalCopy <\/a>to handle this situation, but then realised that it was in the folder I recently messed with only. I then got he idea that with a little luck <strong>moving the images to a different folder and back on the internal memory fixed it<\/strong>, and it did!<\/p>\n<p>Googling for this, it seems to be a known quite old bug, at least back to <a href=\"https:\/\/sourceforge.net\/p\/libmtp\/mailman\/message\/29863222\/\" target=\"_blank\" rel=\"noopener\">2012<\/a> and <a href=\"https:\/\/github.com\/phatina\/simple-mtpfs\/issues\/16\" target=\"_blank\" rel=\"noopener\">2013<\/a>,\u00a0 but it is a rather elusive one, that has been hard to provoke\/reproduce and thus fix&#8230;.<\/p>\n<p>Of course since reading to the end of the streams works, I tried to see if I was allowed to seek in the stream. But this is not allowed, not even seek to the beginning. I do not know if the limitation is in WPD, Android or my specific phablet.<\/p>\n<p>Here a part of the code (from the above linked) that returns the incorrect results<\/p>\n<p><code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Get the size of the object<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/int objSiz;<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 long objSiz;<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 property = new _tagpropertykey();<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 property.fmtid = WPD_OBJECT_;<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 property.pid = 11;\/\/WPD_OBJECT_SIZE;<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/values.GetSignedIntegerValue(property, out objSiz);<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 values.GetSignedLargeIntegerValue(property, out objSiz);<\/code><\/p>\n<p>(Both the Int32 and Int64 call returns the same incorrect sizes)<\/p>\n<p><span style=\"font-size: 8pt;\">PS: The above image was taken from <a href=\"https:\/\/journal.hovatek.com\/how-to-fix-an-android-phones-mass-storage-sd-card-that-wont-connect-to-pc-using-usb-cord\/\" target=\"_blank\" rel=\"noopener\">https:\/\/journal.hovatek.com\/how-to-fix-an-android-phones-mass-storage-sd-card-that-wont-connect-to-pc-using-usb-cord\/<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I stumbled upon a strange bug in what Android can report to e.g. Windows trough the MTP\/WPD interface. Under some circumstances it reports a VERY wrong file size, but if you by WPD open a stream and copy the file until it sends no more bytes, it returns the correct full content.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,6],"tags":[],"class_list":["post-1948","post","type-post","status-publish","format-standard","hentry","category-pc-and-code-samples","category-phonesphablets"],"_links":{"self":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts\/1948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1948"}],"version-history":[{"count":5,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts\/1948\/revisions"}],"predecessor-version":[{"id":2634,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts\/1948\/revisions\/2634"}],"wp:attachment":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}