Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/DataAccess.java @ 399:fdc1db8f7f61 smartgit3
Issue 25: Underflow in InflaterDataAccess; test and fix for hang up when reading past end of compressed data (or zero-length data)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 25 Feb 2012 19:31:57 +0100 |
parents | 5e95b0da26f2 |
children | 528b6780a8bd |
comparison
equal
deleted
inserted
replaced
397:5e95b0da26f2 | 399:fdc1db8f7f61 |
---|---|
30 */ | 30 */ |
31 public class DataAccess { | 31 public class DataAccess { |
32 public boolean isEmpty() { | 32 public boolean isEmpty() { |
33 return true; | 33 return true; |
34 } | 34 } |
35 // TODO throws IOException (few subclasses have non-trivial length() operation) | |
35 public int length() { | 36 public int length() { |
36 return 0; | 37 return 0; |
37 } | 38 } |
38 /** | 39 /** |
39 * get this instance into initial state | 40 * get this instance into initial state |
66 public int readInt() throws IOException { | 67 public int readInt() throws IOException { |
67 byte[] b = new byte[4]; | 68 byte[] b = new byte[4]; |
68 readBytes(b, 0, 4); | 69 readBytes(b, 0, 4); |
69 return b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); | 70 return b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); |
70 } | 71 } |
72 | |
73 /** | |
74 * Read 8 bytes as long value, big-endian. | |
75 */ | |
71 public long readLong() throws IOException { | 76 public long readLong() throws IOException { |
72 byte[] b = new byte[8]; | 77 byte[] b = new byte[8]; |
73 readBytes(b, 0, 8); | 78 readBytes(b, 0, 8); |
74 int i1 = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); | 79 int i1 = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); |
75 int i2 = b[4] << 24 | (b[5] & 0xFF) << 16 | (b[6] & 0xFF) << 8 | (b[7] & 0xFF); | 80 int i2 = b[4] << 24 | (b[5] & 0xFF) << 16 | (b[6] & 0xFF) << 8 | (b[7] & 0xFF); |