Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

fix NUTCH-430

Sami Sirenac4f22864f70
diff --git a/CHANGES.txt b/CHANGES.txt
index c60aa7276..d041067e2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -133,6 +133,9 @@ Unreleased changes (0.9-dev)
43. NUTCH-428 - NullPointerException thrown when agent name is not
configured properly. Changed to throw RuntimeException instead.
+ (siren)
+
+44. NUTCH-430 - Integer overflow in HashComparator.compare (siren)
Release 0.8 - 2006-07-25
diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.java
index 6ee9734dd..d8c0dc575 100644
--- a/src/java/org/apache/nutch/crawl/Generator.java
+++ b/src/java/org/apache/nutch/crawl/Generator.java
@@ -264,39 +264,33 @@ public class Generator extends ToolBase {
output.collect(entry.url, entry.datum);
}
}
-
+
/** Sort fetch lists by hash of URL. */
public static class HashComparator extends WritableComparator {
- public HashComparator() { super(Text.class); }
+ public HashComparator() {
+ super(Text.class);
+ }
public int compare(WritableComparable a, WritableComparable b) {
- Text url1 = (Text)a;
- Text url2 = (Text)b;
+ Text url1 = (Text) a;
+ Text url2 = (Text) b;
int hash1 = hash(url1.getBytes(), 0, url1.getLength());
int hash2 = hash(url2.getBytes(), 0, url2.getLength());
- if (hash1 != hash2) {
- return hash1 - hash2;
- }
- return compareBytes(url1.getBytes(), 0, url1.getLength(),
- url2.getBytes(), 0, url2.getLength());
+ return (hash1 < hash2 ? -1 : (hash1 == hash2 ? 0 : 1));
}
-
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
int hash1 = hash(b1, s1, l1);
int hash2 = hash(b2, s2, l2);
- if (hash1 != hash2) {
- return hash1 - hash2;
- }
- return compareBytes(b1, s1, l1, b2, s2, l2);
+ return (hash1 < hash2 ? -1 : (hash1 == hash2 ? 0 : 1));
}
private static int hash(byte[] bytes, int start, int length) {
int hash = 1;
// make later bytes more significant in hash code, so that sorting by
// hashcode correlates less with by-host ordering.
- for (int i = length-1; i >= 0; i--)
- hash = (31 * hash) + (int)bytes[start+i];
+ for (int i = length - 1; i >= 0; i--)
+ hash = (31 * hash) + (int) bytes[start + i];
return hash;
}
}