From 6a94fe7225cf9b30599092b81a85be644786bb03 Mon Sep 17 00:00:00 2001 From: srowen Date: Wed, 26 Sep 2012 17:40:30 +0000 Subject: [PATCH] Avoid exception when someone scans a file:/// URL barcode. And don't process it. git-svn-id: https://zxing.googlecode.com/svn/trunk@2420 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../com/google/zxing/client/android/HttpHelper.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/src/com/google/zxing/client/android/HttpHelper.java b/android/src/com/google/zxing/client/android/HttpHelper.java index 9af6d4be8..048d54d96 100644 --- a/android/src/com/google/zxing/client/android/HttpHelper.java +++ b/android/src/com/google/zxing/client/android/HttpHelper.java @@ -90,7 +90,11 @@ public final class HttpHelper { private static CharSequence downloadViaHttp(String uri, String contentTypes, int maxChars) throws IOException { Log.i(TAG, "Downloading " + uri); URL url = new URL(uri); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + URLConnection conn = url.openConnection(); + if (!(conn instanceof HttpURLConnection)) { + throw new IOException(); + } + HttpURLConnection connection = (HttpURLConnection) conn; connection.setRequestProperty("Accept", contentTypes); connection.setRequestProperty("Accept-Charset", "utf-8,*"); connection.setRequestProperty("User-Agent", "ZXing (Android)"); @@ -151,7 +155,11 @@ public final class HttpHelper { } URL url = uri.toURL(); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + URLConnection conn = url.openConnection(); + if (!(conn instanceof HttpURLConnection)) { + throw new IOException(); + } + HttpURLConnection connection = (HttpURLConnection) conn; connection.setInstanceFollowRedirects(false); connection.setDoInput(false); connection.setRequestMethod("HEAD");