From da1f279509dc11b436818d0ef0b0bfb49d147fa0 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Thu, 17 Nov 2016 16:02:36 -0800 Subject: [PATCH] adb: fix progress percentage when pulling symlinks. The adb protocol currently only supports lstat with no way of finding the target of a symlink, so pulling a symlink that points to a file looks like pulling a file with length equal to the length of path to the symlink's target. Pulling a file that's sufficiently large can overflow the int used to calculate percentage, and result in a bogus completion percentage being displayed. Bug: http://b/29277448 Test: adb pull /dev/block/platform/soc.0/f9824900.sdhci/by-name/system Change-Id: I42d180550ac2aa9e4705676ccbb20f5db789fb8d --- adb/file_sync_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adb/file_sync_client.cpp b/adb/file_sync_client.cpp index f1e4179c3..115095c9a 100644 --- a/adb/file_sync_client.cpp +++ b/adb/file_sync_client.cpp @@ -149,7 +149,7 @@ struct TransferLedger { void ReportProgress(LinePrinter& lp, const std::string& file, uint64_t file_copied_bytes, uint64_t file_total_bytes) { char overall_percentage_str[5] = "?"; - if (bytes_expected != 0) { + if (bytes_expected != 0 && bytes_transferred <= bytes_expected) { int overall_percentage = static_cast(bytes_transferred * 100 / bytes_expected); // If we're pulling symbolic links, we'll pull the target of the link rather than // just create a local link, and that will cause us to go over 100%.