Merge pull request #1765 from jlipps/fix-max-stack

fix max call stack in keytool zip issue
This commit is contained in:
bootstraponline
2014-01-16 19:36:05 -08:00

View File

@@ -365,12 +365,48 @@ ADB.prototype.checkApkKeystoreMatch = function(keytool, md5re, keystoreHash,
var zip = new AdmZip(apk);
var rsa = /^META-INF\/.*\.[rR][sS][aA]$/;
var entries = zip.getEntries();
var responded = false;
var examined = 0;
var next = function() {
var onExamine = function(err, matched) {
examined++;
if (!responded) {
if (err) {
responded = true;
return cb(err);
} else if (matched) {
responded = true;
return cb(null, true);
} else if (examined === entries.length) {
responded = true;
return cb(null, false);
}
}
};
var checkMd5 = function(err, stdout) {
if (responded) return;
entryHash = md5re.exec(stdout);
entryHash = entryHash ? entryHash[1] : null;
logger.debug('entryHash MD5: ' + entryHash);
logger.debug(' keystore MD5: ' + keystoreHash);
var matchesKeystore = entryHash && entryHash === keystoreHash;
logger.debug('Matches keystore? ' + matchesKeystore);
if (matchesKeystore) {
onExamine(null, true);
} else {
onExamine(null, false);
}
};
for (var i = 0; i < entries.length; i++) {
if (responded) break;
var entry = entries.pop(); // meta-inf tends to be at the end
if (!entry) return cb(null, false); // no more entries
entry = entry.entryName;
if (!rsa.test(entry)) return next();
if (!rsa.test(entry)) {
onExamine(null, false);
continue;
}
logger.debug("Entry: " + entry);
var entryPath = path.join(getTempPath(), pkg, 'cert');
logger.debug("entryPath: " + entryPath);
@@ -384,22 +420,8 @@ ADB.prototype.checkApkKeystoreMatch = function(keytool, md5re, keystoreHash,
// check for match
var md5Entry = [keytool, '-v', '-printcert', '-file', entryFile].join(' ');
logger.debug("Printing apk md5: " + md5Entry);
exec(md5Entry, { maxBuffer: 524288 }, function(err, stdout) {
entryHash = md5re.exec(stdout);
entryHash = entryHash ? entryHash[1] : null;
logger.debug('entryHash MD5: ' + entryHash);
logger.debug(' keystore MD5: ' + keystoreHash);
var matchesKeystore = entryHash && entryHash === keystoreHash;
logger.debug('Matches keystore? ' + matchesKeystore);
if (matchesKeystore) {
return cb(null, true);
} else {
next();
}
});
}.bind(this);
next();
exec(md5Entry, { maxBuffer: 524288 }, checkMd5);
}
};
ADB.prototype.getDevicesWithRetry = function(timeoutMs, cb) {