Changeset 945

Show
Ignore:
Timestamp:
2008-04-15 19:44:56 (7 months ago)
Author:
MaierMan
Message:

#684: DTA reports invalid MD5 checksum on confirmed valid MD5 on big (4 GiB) size file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0.x/chrome/content/dta/manager/verificator.js

    r621 r945  
    4141        this.download = download; 
    4242        this.file = new FileFactory(download.destinationFile); 
     43        this._pending = this.file.fileSize; 
    4344        this.CH = Ci.nsICryptoHash; 
    4445 
     
    5455                 
    5556                this.stream = new FileInputStream(this.file, 0x01, 0766, 0); 
    56                 this.pump = new InputStreamPump(this.stream, 0, -1, 0, 0, true); 
    57                 this.pump.asyncRead(this, null); 
     57                this.download.partialSize = 0; 
     58                this._readNextChunk(); 
     59         
     60                var thisp = this; 
     61                this._timer = new Timer(function() { thisp.download.invalidate(); }, STREAMS_FREQ, true); 
    5862        } 
    5963        catch (ex) { 
     
    8084                } 
    8185        }, 
     86        _finish: function() {                    
     87                        this.download.partialSize = this.download.totalSize; 
     88                        this.download.invalidate(); 
     89                         
     90                        this.hash = hexdigest(this.hash.finish(false)); 
     91                        if (this.hash != this.download.hash.sum) { 
     92                                Debug.dump("hash mismatch, actual: " + this.hash + " expected: " + this.download.hash.sum); 
     93                                var act = DTA_confirm(_('verifyerrortitle'), _('verifyerrortext'), _('retry'), _('delete'), _('keep')); 
     94                                switch (act) { 
     95                                        case 0: this._delete(); this.download.safeRetry(); return; 
     96                                        case 1: this._delete(); this.download.cancel(); return; 
     97                                } 
     98                        } 
     99                        this.download.complete(); 
     100        }, 
     101        _readNextChunk: function() { 
     102                if (this._pending <= 0) { 
     103                        this.stream.close(); 
     104                        this._timer.kill(); 
     105                        var thisp = this; 
     106                        setTimeout(function() { thisp._finish(); }, 100); 
     107                        return; 
     108                } 
     109                var nextChunk = Math.min(this._pending, 1024 /* 2GB */); 
     110                this._pending -= nextChunk; 
     111                new InputStreamPump(this.stream, -1, nextChunk, 0, 0, false).asyncRead(this, null);              
     112        }, 
    82113        _invalidate: function() { 
    83114                this.download.invalidate(); 
     
    90121        }, 
    91122        onStartRequest: function(r, c) { 
    92                 var thisp = this; 
    93                 this._timer = new Timer(function() { thisp.download.invalidate(); }, STREAMS_FREQ, true); 
    94123        }, 
    95124        onStopRequest: function(request, c) { 
    96                 this._timer.kill(); 
    97                  
    98                 this.download.partialSize = this.download.totalSize; 
    99                 this.download.invalidate(); 
    100                  
    101                 this.hash = hexdigest(this.hash.finish(false)); 
    102                 if (this.hash != this.download.hash.sum) { 
    103                         var act = DTA_confirm(_('verifyerrortitle'), _('verifyerrortext'), _('retry'), _('delete'), _('keep')); 
    104                         switch (act) { 
    105                                 case 0: this._delete(); this.download.retry(); return; 
    106                                 case 1: this._delete(); this.download.cancel(); return; 
    107                         } 
    108                 } 
    109                 this.download.complete(); 
     125                this._readNextChunk(); 
    110126        }, 
    111127        onDataAvailable: function(request, c, stream, offset, count) { 
    112128                try { 
    113129                        this.hash.updateFromStream(stream, count); 
    114                         this.download.partialSize = offset; 
     130                        this.download.partialSize += count; 
    115131                } 
    116132                catch (ex) {