diff options
author | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:38:33 +0000 |
---|---|---|
committer | initial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-27 00:38:33 +0000 |
commit | 584cd5cbd7be997400ccb8db24ae5410b0b88117 (patch) | |
tree | 083e5f1f48d019e0f07b96fef7179483df53c823 /third_party/bspatch | |
parent | f5b16fed647e941aa66933178da85db2860d639b (diff) | |
download | chromium_src-584cd5cbd7be997400ccb8db24ae5410b0b88117.zip chromium_src-584cd5cbd7be997400ccb8db24ae5410b0b88117.tar.gz chromium_src-584cd5cbd7be997400ccb8db24ae5410b0b88117.tar.bz2 |
Add third_party to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/bspatch')
-rw-r--r-- | third_party/bspatch/LICENSE | 1 | ||||
-rw-r--r-- | third_party/bspatch/README.google | 10 | ||||
-rw-r--r-- | third_party/bspatch/SConscript | 58 | ||||
-rw-r--r-- | third_party/bspatch/bspatch.vcproj | 50 | ||||
-rw-r--r-- | third_party/bspatch/mbspatch.cc | 234 | ||||
-rw-r--r-- | third_party/bspatch/mbspatch.h | 112 | ||||
-rw-r--r-- | third_party/bspatch/using_bspatch.vsprops | 11 |
7 files changed, 476 insertions, 0 deletions
diff --git a/third_party/bspatch/LICENSE b/third_party/bspatch/LICENSE new file mode 100644 index 0000000..b741c73 --- /dev/null +++ b/third_party/bspatch/LICENSE @@ -0,0 +1 @@ +See ../bsdiff/LICENSE. diff --git a/third_party/bspatch/README.google b/third_party/bspatch/README.google new file mode 100644 index 0000000..9f26265 --- /dev/null +++ b/third_party/bspatch/README.google @@ -0,0 +1,10 @@ +This is Chrome's locally patched copy of Colin Percival's bspatch tool +(see ../bsdiff for the corresponding bsdiff tool). + +Originally obtained from Mozilla's local copy/fork of bspatch; see: + +http://lxr.mozilla.org/mozilla/source/toolkit/mozapps/update/src/updater/ + +The license is shared in common with bsdiff. + +Local changes include CRC32 verification. diff --git a/third_party/bspatch/SConscript b/third_party/bspatch/SConscript new file mode 100644 index 0000000..3889ea6 --- /dev/null +++ b/third_party/bspatch/SConscript @@ -0,0 +1,58 @@ +# Copyright 2008, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Import('env')
+
+env = env.Clone(
+)
+
+env.Prepend(
+ CPPPATH = [
+ '#../third_party/lzma_sdk/',
+ ],
+)
+
+env.Append(
+ CPPDEFINES = [
+ '_LZMA_IN_CB',
+ ],
+ CCFLAGS = [
+ '/TP',
+
+ '/wd4800',
+ '/wd4503',
+ '/wd4819',
+ ],
+)
+
+input_files = Split('''
+ mbspatch.cc
+''')
+
+env.StaticLibrary('bspatch', input_files)
diff --git a/third_party/bspatch/bspatch.vcproj b/third_party/bspatch/bspatch.vcproj new file mode 100644 index 0000000..a3bed7d --- /dev/null +++ b/third_party/bspatch/bspatch.vcproj @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="bspatch" + ProjectGUID="{D7ED06E8-6138-4CE3-A906-5EF1D9C804E0}" + RootNamespace="bspatch" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + ConfigurationType="4" + InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;$(SolutionDir)..\build\external_code.vsprops;$(SolutionDir)..\third_party\bspatch\using_bspatch.vsprops;$(SolutionDir)..\third_party\lzma_sdk\using_lzma_sdk.vsprops" + > + <Tool + Name="VCCLCompilerTool" + /> + <Tool + Name="VCLibrarianTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + ConfigurationType="4" + InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;$(SolutionDir)..\build\external_code.vsprops;$(SolutionDir)..\third_party\bspatch\using_bspatch.vsprops;$(SolutionDir)..\third_party\lzma_sdk\using_lzma_sdk.vsprops" + > + <Tool + Name="VCCLCompilerTool" + /> + <Tool + Name="VCLibrarianTool" + /> + </Configuration> + </Configurations> + <Files> + <File + RelativePath=".\mbspatch.cc" + > + </File> + <File + RelativePath=".\mbspatch.h" + > + </File> + </Files> +</VisualStudioProject> diff --git a/third_party/bspatch/mbspatch.cc b/third_party/bspatch/mbspatch.cc new file mode 100644 index 0000000..2b4d76a --- /dev/null +++ b/third_party/bspatch/mbspatch.cc @@ -0,0 +1,234 @@ +/*- + * Copyright 2003,2004 Colin Percival + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted providing that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Changelog: + * 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to + * the header, and make all the types 32-bit. + * --Benjamin Smedberg <benjamin@smedbergs.us> + * 2007-11-14 - Added CalculateCrc() and ApplyBinaryPatch() methods. + * --Rahul Kuchhal + */ + +#include "mbspatch.h" + +#include <sys/stat.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <string.h> +#include <limits.h> + +#ifdef _WIN32 +# include <io.h> +# include <winsock2.h> +#else +# include <unistd.h> +# include <arpa/inet.h> +#endif + +extern "C" { +#include <7zCrc.h> +} + +#ifndef SSIZE_MAX +# define SSIZE_MAX LONG_MAX +#endif + +int +MBS_ReadHeader(int fd, MBSPatchHeader *header) +{ + int s = read(fd, header, sizeof(MBSPatchHeader)); + if (s != sizeof(MBSPatchHeader)) + return READ_ERROR; + + header->slen = ntohl(header->slen); + header->scrc32 = ntohl(header->scrc32); + header->dlen = ntohl(header->dlen); + header->cblen = ntohl(header->cblen); + header->difflen = ntohl(header->difflen); + header->extralen = ntohl(header->extralen); + + struct stat hs; + s = fstat(fd, &hs); + if (s) + return READ_ERROR; + + if (memcmp(header->tag, "MBDIFF10", 8) != 0) + return UNEXPECTED_ERROR; + + if (sizeof(MBSPatchHeader) + + header->cblen + + header->difflen + + header->extralen != int(hs.st_size)) + return UNEXPECTED_ERROR; + + return OK; +} + +int +MBS_ApplyPatch(const MBSPatchHeader *header, int patchfd, + unsigned char *fbuffer, int filefd) +{ + unsigned char *fbufend = fbuffer + header->slen; + + unsigned char *buf = (unsigned char*) malloc(header->cblen + + header->difflen + + header->extralen); + if (!buf) + return MEM_ERROR; + + int rv = OK; + + int r = header->cblen + header->difflen + header->extralen; + unsigned char *wb = buf; + while (r) { + int c = read(patchfd, wb, (r > SSIZE_MAX) ? SSIZE_MAX : r); + if (c < 0) { + rv = READ_ERROR; + goto end; + } + + r -= c; + + if (c == 0 && r) { + rv = UNEXPECTED_ERROR; + goto end; + } + } + + { + MBSPatchTriple *ctrlsrc = (MBSPatchTriple*) buf; + unsigned char *diffsrc = buf + header->cblen; + unsigned char *extrasrc = diffsrc + header->difflen; + + MBSPatchTriple *ctrlend = (MBSPatchTriple*) diffsrc; + unsigned char *diffend = extrasrc; + unsigned char *extraend = extrasrc + header->extralen; + + do { + ctrlsrc->x = ntohl(ctrlsrc->x); + ctrlsrc->y = ntohl(ctrlsrc->y); + ctrlsrc->z = ntohl(ctrlsrc->z); + +#ifdef DEBUG_bsmedberg + printf("Applying block:\n" + " x: %u\n" + " y: %u\n" + " z: %i\n", + ctrlsrc->x, + ctrlsrc->y, + ctrlsrc->z); +#endif + + /* Add x bytes from oldfile to x bytes from the diff block */ + + if (fbuffer + ctrlsrc->x > fbufend || + diffsrc + ctrlsrc->x > diffend) { + rv = UNEXPECTED_ERROR; + goto end; + } + for (unsigned int i = 0; i < ctrlsrc->x; ++i) { + diffsrc[i] += fbuffer[i]; + } + if ((int) write(filefd, diffsrc, ctrlsrc->x) != ctrlsrc->x) { + rv = WRITE_ERROR; + goto end; + } + fbuffer += ctrlsrc->x; + diffsrc += ctrlsrc->x; + + /* Copy y bytes from the extra block */ + + if (extrasrc + ctrlsrc->y > extraend) { + rv = UNEXPECTED_ERROR; + goto end; + } + if ((int) write(filefd, extrasrc, ctrlsrc->y) != ctrlsrc->y) { + rv = WRITE_ERROR; + goto end; + } + extrasrc += ctrlsrc->y; + + /* "seek" forwards in oldfile by z bytes */ + + if (fbuffer + ctrlsrc->z > fbufend) { + rv = UNEXPECTED_ERROR; + goto end; + } + fbuffer += ctrlsrc->z; + + /* and on to the next control block */ + + ++ctrlsrc; + } while (ctrlsrc < ctrlend); + } + +end: + free(buf); + return rv; +} + +int CalculateCrc(const unsigned char *buf, int size) { + CrcGenerateTable(); + unsigned int crc = 0xffffffffL; + crc = ~CrcCalc(buf, size); + return crc; +} + +int ApplyBinaryPatch(const char *old_file, const char *patch_file, + const char *new_file) { + int ret = 0; + int pfd = open(patch_file, O_RDONLY | _O_BINARY); + if (pfd < 0) return READ_ERROR; + + MBSPatchHeader header; + if (ret = MBS_ReadHeader(pfd, &header)) return ret; + + int ofd = open(old_file, O_RDONLY | _O_BINARY); + if (ofd < 0) return READ_ERROR; + + struct stat os; + if (ret = fstat(ofd, &os)) return READ_ERROR; + if (os.st_size != header.slen) return UNEXPECTED_ERROR; + + unsigned char *buf = (unsigned char*) malloc(header.slen); + if (!buf) return MEM_ERROR; + + if (read(ofd, buf, header.slen) != header.slen) return READ_ERROR; + if (CalculateCrc(buf, header.slen) != header.scrc32) + return CRC_ERROR; + + int nfd = open(new_file, O_WRONLY | O_TRUNC | O_CREAT | _O_BINARY); + if (nfd < 0) return READ_ERROR; + + MBS_ApplyPatch(&header, pfd, buf, nfd); + + free(buf); + close(pfd); + close(ofd); + close(nfd); + return OK; +} + diff --git a/third_party/bspatch/mbspatch.h b/third_party/bspatch/mbspatch.h new file mode 100644 index 0000000..9e5123b --- /dev/null +++ b/third_party/bspatch/mbspatch.h @@ -0,0 +1,112 @@ +/*- + * Copyright 2003,2004 Colin Percival + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted providing that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Changelog: + * 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to + * the header, and make all the types 32-bit. + * --Benjamin Smedberg <benjamin@smedbergs.us> + */ + +#ifndef bspatch_h__ +#define bspatch_h__ + +#define OK 0 +#define MEM_ERROR 1 +// #define IO_ERROR 2 // Use READ_ERROR or WRITE_ERROR instead +#define USAGE_ERROR 3 +#define CRC_ERROR 4 +#define PARSE_ERROR 5 +#define READ_ERROR 6 +#define WRITE_ERROR 7 +#define UNEXPECTED_ERROR 8 + +typedef struct MBSPatchHeader_ { + /* "MBDIFF10" */ + char tag[8]; + + /* Length of the file to be patched */ + unsigned int slen; + + /* CRC32 of the file to be patched */ + unsigned int scrc32; + + /* Length of the result file */ + unsigned int dlen; + + /* Length of the control block in bytes */ + unsigned int cblen; + + /* Length of the diff block in bytes */ + unsigned int difflen; + + /* Length of the extra block in bytes */ + unsigned int extralen; + + /* Control block (MBSPatchTriple[]) */ + /* Diff block (binary data) */ + /* Extra block (binary data) */ +} MBSPatchHeader; + +/** + * Read the header of a patch file into the MBSPatchHeader structure. + * + * @param fd Must have been opened for reading, and be at the beginning + * of the file. + */ +int MBS_ReadHeader(int fd, MBSPatchHeader *header); + +/** + * Apply a patch. This method does not validate the checksum of the original + * file: client code should validate the checksum before calling this method. + * + * @param patchfd Must have been processed by MBS_ReadHeader + * @param fbuffer The original file read into a memory buffer of length + * header->slen. + * @param filefd Must have been opened for writing. Should be truncated + * to header->dlen if it is an existing file. The offset + * should be at the beginning of the file. + */ +int MBS_ApplyPatch(const MBSPatchHeader *header, int patchfd, + unsigned char *fbuffer, int filefd); + +typedef struct MBSPatchTriple_ { + unsigned int x; /* add x bytes from oldfile to x bytes from the diff block */ + unsigned int y; /* copy y bytes from the extra block */ + int z; /* seek forwards in oldfile by z bytes */ +} MBSPatchTriple; + +/** + * Apply the given patch file to a given source file. This method validates + * the CRC of the original file stored in the patch file, before applying the + * patch to it. + */ +int ApplyBinaryPatch(const char *old_file, const char *patch_file, + const char *new_file); + +/** + * Calculates Crc of the given buffer by calling CRC method in LZMA SDK + */ +int CalculateCrc(const unsigned char *buf, int size); +#endif // bspatch_h__ diff --git a/third_party/bspatch/using_bspatch.vsprops b/third_party/bspatch/using_bspatch.vsprops new file mode 100644 index 0000000..d13953d --- /dev/null +++ b/third_party/bspatch/using_bspatch.vsprops @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioPropertySheet + ProjectType="Visual C++" + Version="8.00" + Name="using_bspatch" + > + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories=""$(SolutionDir)..\third_party\bspatch"" + /> +</VisualStudioPropertySheet> |