From b40d2e9f73af9ebf6df94436edf2f7dcff4702fe Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 11 Jun 2015 20:00:37 +0200 Subject: [PATCH] Fixed issue #8 - search for MAGIC bytes instead of just checking (NOW it should work) --- .../java/ch/dissem/bitmessage/factory/V3MessageFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/domain/src/main/java/ch/dissem/bitmessage/factory/V3MessageFactory.java b/domain/src/main/java/ch/dissem/bitmessage/factory/V3MessageFactory.java index a9848b6..2ba0f9d 100644 --- a/domain/src/main/java/ch/dissem/bitmessage/factory/V3MessageFactory.java +++ b/domain/src/main/java/ch/dissem/bitmessage/factory/V3MessageFactory.java @@ -201,13 +201,15 @@ class V3MessageFactory { for (int i = 0; i < 1620000; i++) { byte b = (byte) in.read(); if (b == MAGIC_BYTES[pos]) { - pos++; - if (pos == MAGIC_BYTES.length) { + if (pos + 1 == MAGIC_BYTES.length) { return; } + } else if (pos > 0 && b == MAGIC_BYTES[0]) { + pos = 1; } else { pos = 0; } + pos++; } throw new IOException("Failed to fine MAGIC bytes in stream"); }