From a3f40da51cd3a3ec9ee15d95f93c0cfd19a95b41 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 13 Apr 2022 20:09:42 +0100 Subject: [PATCH] provision for future versions sending profiles with search results --- .../muwire/core/connection/ConnectionAcceptor.groovy | 12 +++++++++++- core/src/main/java/com/muwire/core/Constants.java | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy index 3955bc5e..9d21c683 100644 --- a/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy +++ b/core/src/main/groovy/com/muwire/core/connection/ConnectionAcceptor.groovy @@ -339,6 +339,9 @@ class ConnectionAcceptor { boolean feed = false if (headers.containsKey('Feed')) feed = Boolean.parseBoolean(headers['Feed']) + boolean profile = false + if (headers.containsKey("Profile")) + profile = Boolean.parseBoolean(headers['Profile']) byte [] personaBytes = Base64.decode(headers['Sender']) Persona sender = new Persona(new ByteArrayInputStream(personaBytes)) @@ -348,7 +351,14 @@ class ConnectionAcceptor { int nResults = Integer.parseInt(headers['Count']) if (nResults > Constants.MAX_RESULTS) throw new IOException("too many results $nResults") - + + if (profile) { + int profileLength = dis.readInt() + if (profileLength > Constants.MAX_PROFILE_LENGTH) + throw new IOException("profile too large $profileLength") + dis.skipBytes(profileLength) // skip profile data for now + } + dis = new DataInputStream(new GZIPInputStream(dis)) UIResultEvent[] results = new UIResultEvent[Math.min(RESULT_BATCH_SIZE, nResults)] int j = 0 diff --git a/core/src/main/java/com/muwire/core/Constants.java b/core/src/main/java/com/muwire/core/Constants.java index e995dcea..8b0e91f9 100644 --- a/core/src/main/java/com/muwire/core/Constants.java +++ b/core/src/main/java/com/muwire/core/Constants.java @@ -23,6 +23,7 @@ public class Constants { public static final long MAX_HEADER_TIME = 60 * 1000; public static final int MAX_RESULTS = 0x1 << 20; + public static final int MAX_PROFILE_LENGTH = 0x1 << 18; public static final int MAX_COMMENT_LENGTH = 0x1 << 15;