Program: 3068
Project: 3068
Buggy source:
public void uploadPhoto(HttpRequest request) throws HttpException, IOException {
  Log.d(TAG,myId + "String_Node_Str" + request.toString());
  HttpEntityEnclosingRequest eyefiRequest=(HttpEntityEnclosingRequest)request;
  Header contentTypes[]=eyefiRequest.getHeaders("String_Node_Str");
  if ((contentTypes == null) || contentTypes.length < 1) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  HeaderElement elements[]=contentTypes[0].getElements();
  if ((elements == null) || elements.length < 1) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  if (!elements[0].getName().equals("String_Node_Str")) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  String b="String_Node_Str";
  String value=contentTypes[0].getValue();
  int pos=value.indexOf(b);
  if (pos < 0) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  String boundary="String_Node_Str" + value.substring(pos + b.length()) + "String_Node_Str";
  Log.d(TAG,myId + "String_Node_Str" + boundary);
  receiveRequestEntity(eyefiRequest);
  HttpEntity entity=eyefiRequest.getEntity();
  MultipartInputStream in=new MultipartInputStream(new BufferedInputStream(entity.getContent(),400000),boundary);
  in.close();
  Map<String,String> headers=in.getHeaders();
  UploadPhoto uploadPhoto=null;
  String fileSignature=null;
  String imageName=null;
  File destinationPath=null;
  long id=-1;
  boolean success=false;
  String readDigest=null, calculatedDigest=null;
  Vector<File> written=new Vector<File>();
  String fileName=null;
  while (!headers.isEmpty()) {
    String contentDisposition=headers.get("String_Node_Str");
    if (contentDisposition == null)     break;
    if (!contentDisposition.startsWith(CONTENT_DISPOSITION_PREAMBLE))     break;
    int endPos=contentDisposition.indexOf('"',CONTENT_DISPOSITION_PREAMBLE.length());
    if (endPos < 0)     break;
    String partName=contentDisposition.substring(CONTENT_DISPOSITION_PREAMBLE.length(),endPos);
    Log.d(TAG,myId + "String_Node_Str" + partName);
    if (partName.equals("String_Node_Str")) {
      UploadPhoto u=new UploadPhoto();
      u.parse(in);
      uploadPhoto=u;
      Log.d(TAG,myId + "String_Node_Str");
    }
 else     if (partName.equals("String_Node_Str")) {
      EyefiIntegrityDigest checksum=new EyefiIntegrityDigest();
      TarInputStream tarball=new TarInputStream(new CheckedInputStream(in,checksum));
      TarEntry file=tarball.getNextEntry();
      while (file != null) {
        fileName=file.getName();
        Log.d(TAG,myId + "String_Node_Str" + fileName+ "String_Node_Str"+ file.getSize()+ "String_Node_Str");
        if (fileName.endsWith("String_Node_Str")) {
          File destination=openWritableFile(id,"String_Node_Str");
          copyToLocalFile(tarball,destination);
          written.add(destination);
        }
 else {
          if (uploadPhoto == null) {
            Log.d(TAG,myId + "String_Node_Str");
            break;
          }
          fileSignature=uploadPhoto.getParameter(EyefiMessage.FILESIGNATURE);
          imageName=fileName;
          try {
            try {
              id=db.imageUploadable(fileSignature);
            }
 catch (            DBAdapter.UnknownUpload e) {
              fileSignature=fileSignature + "String_Node_Str" + fileName;
              Log.d(TAG,myId + "String_Node_Str" + fileSignature);
              db.registerNewImage(fileSignature);
              id=db.imageUploadable(fileSignature);
            }
            Log.d(TAG,myId + "String_Node_Str" + fileName+ "String_Node_Str"+ fileSignature+ "String_Node_Str"+ id);
            destinationPath=openWritableFile(id,"String_Node_Str");
            Log.d(TAG,myId + "String_Node_Str" + imageName+ "String_Node_Str"+ destinationPath);
            copyToLocalFile(tarball,destinationPath);
            written.add(destinationPath);
            success=true;
          }
 catch (          IOException e) {
            Log.e(TAG,myId + "String_Node_Str" + e);
          }
catch (          DBAdapter.DuplicateUpload e) {
            Log.e(TAG,myId + "String_Node_Str");
            success=true;
          }
catch (          DBAdapter.UnknownUpload e) {
            Log.e(TAG,myId + "String_Node_Str" + uploadPhoto);
          }
        }
        Log.d(TAG,myId + "String_Node_Str");
        file=tarball.getNextEntry();
      }
      UploadKey uploadKey=getKeyForMac(uploadPhoto.getMacAddress());
      calculatedDigest=checksum.getValue(uploadKey).toString();
      Log.d(TAG,myId + "String_Node_Str" + calculatedDigest);
    }
 else     if (partName.equals("String_Node_Str")) {
      BufferedReader r=new BufferedReader(new InputStreamReader(in));
      readDigest=r.readLine();
      Log.d(TAG,myId + "String_Node_Str" + readDigest);
    }
    in.close();
    headers=in.getHeaders();
  }
  if (calculatedDigest == null) {
    Log.d(TAG,myId + "String_Node_Str");
    success=false;
  }
  if (readDigest == null) {
    Log.d(TAG,myId + "String_Node_Str");
    success=false;
  }
  if (success && !readDigest.equals(calculatedDigest)) {
    Log.d(TAG,myId + "String_Node_Str");
    success=false;
  }
  if (success && destinationPath != null) {
    Uri uri=importPhoto(destinationPath,fileName,id);
    db.receiveImage(id,imageName,destinationPath.toString());
    db.finishImage(id,uri);
  }
  if (!success)   for (  File f : written)   f.delete();
  UploadPhotoResponse response=new UploadPhotoResponse(success);
  sendResponseHeader(response);
  sendResponseEntity(response);
}

Fixed version (ground truth):
public void uploadPhoto(HttpRequest request) throws HttpException, IOException {
  Log.d(TAG,myId + "String_Node_Str" + request.toString());
  HttpEntityEnclosingRequest eyefiRequest=(HttpEntityEnclosingRequest)request;
  Header contentTypes[]=eyefiRequest.getHeaders("String_Node_Str");
  if ((contentTypes == null) || contentTypes.length < 1) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  HeaderElement elements[]=contentTypes[0].getElements();
  if ((elements == null) || elements.length < 1) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  if (!elements[0].getName().equals("String_Node_Str")) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  String b="String_Node_Str";
  String value=contentTypes[0].getValue();
  int pos=value.indexOf(b);
  if (pos < 0) {
    Log.e(TAG,myId + "String_Node_Str");
    close();
  }
  String boundary="String_Node_Str" + value.substring(pos + b.length());
  Log.d(TAG,myId + "String_Node_Str" + boundary);
  receiveRequestEntity(eyefiRequest);
  HttpEntity entity=eyefiRequest.getEntity();
  MultipartInputStream in=new MultipartInputStream(new BufferedInputStream(entity.getContent(),400000),boundary);
  in.close();
  Map<String,String> headers=in.getHeaders();
  UploadPhoto uploadPhoto=null;
  String fileSignature=null;
  String imageName=null;
  File destinationPath=null;
  long id=-1;
  boolean success=false;
  String readDigest=null, calculatedDigest=null;
  Vector<File> written=new Vector<File>();
  String fileName=null;
  while (!headers.isEmpty()) {
    String contentDisposition=headers.get("String_Node_Str");
    if (contentDisposition == null)     break;
    if (!contentDisposition.startsWith(CONTENT_DISPOSITION_PREAMBLE))     break;
    int endPos=contentDisposition.indexOf('"',CONTENT_DISPOSITION_PREAMBLE.length());
    if (endPos < 0)     break;
    String partName=contentDisposition.substring(CONTENT_DISPOSITION_PREAMBLE.length(),endPos);
    Log.d(TAG,myId + "String_Node_Str" + partName);
    if (partName.equals("String_Node_Str")) {
      UploadPhoto u=new UploadPhoto();
      u.parse(in);
      uploadPhoto=u;
      Log.d(TAG,myId + "String_Node_Str");
    }
 else     if (partName.equals("String_Node_Str")) {
      EyefiIntegrityDigest checksum=new EyefiIntegrityDigest();
      CheckedInputStream c=new CheckedInputStream(in,checksum);
      TarInputStream tarball=new TarInputStream(c);
      TarEntry file=tarball.getNextEntry();
      while (file != null) {
        fileName=file.getName();
        Log.d(TAG,myId + "String_Node_Str" + fileName+ "String_Node_Str"+ file.getSize()+ "String_Node_Str");
        if (fileName.endsWith("String_Node_Str")) {
          File destination=openWritableFile(id,"String_Node_Str");
          copyToLocalFile(tarball,destination);
          written.add(destination);
        }
 else {
          if (uploadPhoto == null) {
            Log.d(TAG,myId + "String_Node_Str");
            break;
          }
          fileSignature=uploadPhoto.getParameter(EyefiMessage.FILESIGNATURE);
          imageName=fileName;
          try {
            try {
              id=db.imageUploadable(fileSignature);
            }
 catch (            DBAdapter.UnknownUpload e) {
              fileSignature=fileSignature + "String_Node_Str" + fileName;
              Log.d(TAG,myId + "String_Node_Str" + fileSignature);
              db.registerNewImage(fileSignature);
              id=db.imageUploadable(fileSignature);
            }
            Log.d(TAG,myId + "String_Node_Str" + fileName+ "String_Node_Str"+ fileSignature+ "String_Node_Str"+ id);
            destinationPath=openWritableFile(id,"String_Node_Str");
            Log.d(TAG,myId + "String_Node_Str" + imageName+ "String_Node_Str"+ destinationPath);
            copyToLocalFile(tarball,destinationPath);
            written.add(destinationPath);
            success=true;
          }
 catch (          IOException e) {
            Log.e(TAG,myId + "String_Node_Str" + e);
          }
catch (          DBAdapter.DuplicateUpload e) {
            Log.e(TAG,myId + "String_Node_Str");
            success=true;
          }
catch (          DBAdapter.UnknownUpload e) {
            Log.e(TAG,myId + "String_Node_Str" + uploadPhoto);
          }
        }
        Log.d(TAG,myId + "String_Node_Str");
        file=tarball.getNextEntry();
      }
      c.skip(4096);
      UploadKey uploadKey=getKeyForMac(uploadPhoto.getMacAddress());
      calculatedDigest=checksum.getValue(uploadKey).toString();
      Log.d(TAG,myId + "String_Node_Str" + calculatedDigest);
    }
 else     if (partName.equals("String_Node_Str")) {
      BufferedReader r=new BufferedReader(new InputStreamReader(in));
      readDigest=r.readLine();
      Log.d(TAG,myId + "String_Node_Str" + readDigest);
    }
    in.close();
    headers=in.getHeaders();
  }
  if (calculatedDigest == null) {
    Log.d(TAG,myId + "String_Node_Str");
    success=false;
  }
  if (readDigest == null) {
    Log.d(TAG,myId + "String_Node_Str");
    success=false;
  }
  if (success && !readDigest.equals(calculatedDigest)) {
    Log.d(TAG,myId + "String_Node_Str");
    success=false;
  }
  if (success && destinationPath != null) {
    Uri uri=importPhoto(destinationPath,fileName,id);
    db.receiveImage(id,imageName,destinationPath.toString());
    db.finishImage(id,uri);
  }
  if (!success)   for (  File f : written)   f.delete();
  UploadPhotoResponse response=new UploadPhotoResponse(success);
  sendResponseHeader(response);
  sendResponseEntity(response);
}