Skip to content
Snippets Groups Projects
Unverified Commit b4a83e40 authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #1302 from APriestman/4104_fixExtractReleaseBranch

Test that the image handle is still valid before using it.
parents 12a3be88 4aa94542
No related branches found
No related tags found
No related merge requests found
...@@ -643,6 +643,9 @@ private static long openImage(String[] imageFiles, int sSize, boolean useCache) ...@@ -643,6 +643,9 @@ private static long openImage(String[] imageFiles, int sSize, boolean useCache)
public static long openVs(long imgHandle, long vsOffset) throws TskCoreException { public static long openVs(long imgHandle, long vsOffset) throws TskCoreException {
getTSKReadLock(); getTSKReadLock();
try { try {
if(! imgHandleIsValid(imgHandle)) {
throw new TskCoreException("Image handle " + imgHandle + " is closed");
}
return openVsNat(imgHandle, vsOffset); return openVsNat(imgHandle, vsOffset);
} finally { } finally {
releaseTSKReadLock(); releaseTSKReadLock();
...@@ -756,6 +759,17 @@ private static int convertSignedToUnsigned(int val) { ...@@ -756,6 +759,17 @@ private static int convertSignedToUnsigned(int val) {
return val & 0xffff; // convert negative value to positive value return val & 0xffff; // convert negative value to positive value
} }
/**
* Test that the given image handle is valid.
* @param imgHandle
* @return true if it is valid, false otherwise
*/
private static boolean imgHandleIsValid(long imgHandle) {
synchronized(HandleCache.cacheLock) {
return HandleCache.fsHandleCache.containsKey(imgHandle);
}
}
//do reads //do reads
/** /**
...@@ -775,6 +789,9 @@ private static int convertSignedToUnsigned(int val) { ...@@ -775,6 +789,9 @@ private static int convertSignedToUnsigned(int val) {
public static int readImg(long imgHandle, byte[] readBuffer, long offset, long len) throws TskCoreException { public static int readImg(long imgHandle, byte[] readBuffer, long offset, long len) throws TskCoreException {
getTSKReadLock(); getTSKReadLock();
try { try {
if(! imgHandleIsValid(imgHandle)) {
throw new TskCoreException("Image handle " + imgHandle + " is closed");
}
//returned byte[] is the data buffer //returned byte[] is the data buffer
return readImgNat(imgHandle, readBuffer, offset, len); return readImgNat(imgHandle, readBuffer, offset, len);
} finally { } finally {
...@@ -1226,6 +1243,9 @@ private static String timezoneLongToShort(String timezoneLongForm) { ...@@ -1226,6 +1243,9 @@ private static String timezoneLongToShort(String timezoneLongForm) {
public static int finishImageWriter(long imgHandle) throws TskCoreException { public static int finishImageWriter(long imgHandle) throws TskCoreException {
getTSKReadLock(); getTSKReadLock();
try { try {
if(! imgHandleIsValid(imgHandle)) {
throw new TskCoreException("Image handle " + imgHandle + " is closed");
}
return finishImageWriterNat(imgHandle); return finishImageWriterNat(imgHandle);
} finally { } finally {
releaseTSKReadLock(); releaseTSKReadLock();
...@@ -1242,7 +1262,11 @@ public static int finishImageWriter(long imgHandle) throws TskCoreException { ...@@ -1242,7 +1262,11 @@ public static int finishImageWriter(long imgHandle) throws TskCoreException {
public static int getFinishImageProgress(long imgHandle) { public static int getFinishImageProgress(long imgHandle) {
getTSKReadLock(); getTSKReadLock();
try { try {
return getFinishImageProgressNat(imgHandle); if (imgHandleIsValid(imgHandle)) {
return getFinishImageProgressNat(imgHandle);
} else {
return 0;
}
} finally { } finally {
releaseTSKReadLock(); releaseTSKReadLock();
} }
...@@ -1256,7 +1280,9 @@ public static int getFinishImageProgress(long imgHandle) { ...@@ -1256,7 +1280,9 @@ public static int getFinishImageProgress(long imgHandle) {
public static void cancelFinishImage(long imgHandle) { public static void cancelFinishImage(long imgHandle) {
getTSKReadLock(); getTSKReadLock();
try { try {
cancelFinishImageNat(imgHandle); if (imgHandleIsValid(imgHandle)) {
cancelFinishImageNat(imgHandle);
}
} finally { } finally {
releaseTSKReadLock(); releaseTSKReadLock();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment