fixed bug #1504758 - CRC32 implementation use potentially non-32bit types
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4697 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
618331287c
commit
3e561714e4
7 changed files with 38 additions and 30 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "util.h"
|
||||
#include "fileform.h"
|
||||
#include "writer.h"
|
||||
#include "crc32.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
|
@ -2274,7 +2275,7 @@ int CEXEBuild::write_output(void)
|
|||
|
||||
RET_UNLESS_OK( uninstall_generate() );
|
||||
|
||||
int crc=0;
|
||||
crc32_t crc=0;
|
||||
|
||||
{
|
||||
string full_path = get_full_path(build_output_filename);
|
||||
|
@ -2349,7 +2350,7 @@ int CEXEBuild::write_output(void)
|
|||
}
|
||||
|
||||
if (!build_compress_whole)
|
||||
fh.length_of_all_following_data=ihd.getlen()+build_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(int):0);
|
||||
fh.length_of_all_following_data=ihd.getlen()+build_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(crc32_t):0);
|
||||
else
|
||||
fd_start=ftell(fp);
|
||||
|
||||
|
@ -2384,7 +2385,7 @@ int CEXEBuild::write_output(void)
|
|||
return PS_ERROR;
|
||||
}
|
||||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
crc_writer_sink crc_sink((unsigned long *) &crc);
|
||||
crc_writer_sink crc_sink((crc32_t *) &crc);
|
||||
firstheader_writer w(&crc_sink);
|
||||
w.write(&fh);
|
||||
|
||||
|
@ -2455,7 +2456,7 @@ int CEXEBuild::write_output(void)
|
|||
if (db_opt_save)
|
||||
{
|
||||
int total_out_size_estimate=
|
||||
m_exehead_size+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(int):0);
|
||||
m_exehead_size+sizeof(fh)+build_datablock.getlen()+(build_crcchk?sizeof(crc32_t):0);
|
||||
#ifdef _WIN32
|
||||
int pc=MulDiv(db_opt_save,1000,db_opt_save+total_out_size_estimate);
|
||||
#else
|
||||
|
@ -2564,7 +2565,7 @@ int CEXEBuild::write_output(void)
|
|||
|
||||
unsigned fend = ftell(fp);
|
||||
|
||||
fh.length_of_all_following_data=ftell(fp)-fd_start+(build_crcchk?sizeof(int):0);
|
||||
fh.length_of_all_following_data=ftell(fp)-fd_start+(build_crcchk?sizeof(crc32_t):0);
|
||||
INFO_MSG(
|
||||
"%10d / %d bytes\n",
|
||||
ftell(fp) - fd_start,
|
||||
|
@ -2608,9 +2609,9 @@ int CEXEBuild::write_output(void)
|
|||
{
|
||||
total_usize+=sizeof(int);
|
||||
int rcrc = FIX_ENDIAN_INT32(crc);
|
||||
if (fwrite(&rcrc,1,sizeof(int),fp) != sizeof(int))
|
||||
if (fwrite(&rcrc,1,sizeof(crc32_t),fp) != sizeof(crc32_t))
|
||||
{
|
||||
ERROR_MSG("Error: can't write %d bytes to output\n",sizeof(int));
|
||||
ERROR_MSG("Error: can't write %d bytes to output\n",sizeof(crc32_t));
|
||||
fclose(fp);
|
||||
return PS_ERROR;
|
||||
}
|
||||
|
@ -2693,7 +2694,7 @@ int CEXEBuild::uninstall_generate()
|
|||
if (err < 0) return PS_ERROR;
|
||||
}
|
||||
|
||||
int crc=0;
|
||||
crc32_t crc=0;
|
||||
|
||||
// Get offsets of icons to replace for uninstall
|
||||
// Also makes sure that the icons are there and in the right size.
|
||||
|
@ -2763,7 +2764,7 @@ int CEXEBuild::uninstall_generate()
|
|||
#endif
|
||||
fh.siginfo=FH_SIG;
|
||||
fh.length_of_all_following_data=
|
||||
uhd.getlen()+ubuild_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(int):0);
|
||||
uhd.getlen()+ubuild_datablock.getlen()+(int)sizeof(firstheader)+(build_crcchk?sizeof(crc32_t):0);
|
||||
|
||||
MMapBuf udata;
|
||||
|
||||
|
@ -2832,7 +2833,7 @@ int CEXEBuild::uninstall_generate()
|
|||
}
|
||||
|
||||
firstheader *_fh=(firstheader *)udata.get(0, sizeof(firstheader));
|
||||
_fh->length_of_all_following_data=FIX_ENDIAN_INT32(udata.getlen()+(build_crcchk?sizeof(int):0));
|
||||
_fh->length_of_all_following_data=FIX_ENDIAN_INT32(udata.getlen()+(build_crcchk?sizeof(crc32_t):0));
|
||||
udata.release();
|
||||
}
|
||||
else
|
||||
|
|
|
@ -35,13 +35,6 @@
|
|||
# include "Plugins.h"
|
||||
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
|
||||
|
||||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
extern "C"
|
||||
{
|
||||
unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len);
|
||||
};
|
||||
#endif
|
||||
|
||||
#define PS_OK 0
|
||||
#define PS_EOF 1
|
||||
#define PS_ERROR 50
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
#include "Platform.h"
|
||||
#include "crc32.h"
|
||||
#include "exehead/config.h"
|
||||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
|
||||
// this is based on the (slow,small) CRC32 implementation from zlib.
|
||||
unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len)
|
||||
crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len)
|
||||
{
|
||||
static unsigned long crc_table[256];
|
||||
static crc32_t crc_table[256];
|
||||
|
||||
if (!crc_table[1])
|
||||
{
|
||||
unsigned long c;
|
||||
crc32_t c;
|
||||
int n, k;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = (unsigned long)n;
|
||||
c = (crc32_t)n;
|
||||
for (k = 0; k < 8; k++) c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0);
|
||||
crc_table[n] = c;
|
||||
}
|
||||
|
|
13
Source/crc32.h
Normal file
13
Source/crc32.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "Platform.h"
|
||||
|
||||
#ifndef ___CRC32__H___
|
||||
#define ___CRC32__H___
|
||||
|
||||
typedef UINT32 crc32_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len);
|
||||
|
||||
#endif//!___CRC32__H___
|
|
@ -6,6 +6,7 @@
|
|||
#include "lang.h"
|
||||
#include "ui.h"
|
||||
#include "exec.h"
|
||||
#include "../crc32.h"
|
||||
|
||||
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT
|
||||
#ifdef NSIS_COMPRESS_USE_ZLIB
|
||||
|
@ -95,8 +96,6 @@ BOOL CALLBACK verProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
static z_stream g_inflate_stream;
|
||||
#endif
|
||||
|
||||
extern unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len);
|
||||
|
||||
const char * NSISCALL loadHeaders(int cl_flags)
|
||||
{
|
||||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
|
@ -104,7 +103,7 @@ const char * NSISCALL loadHeaders(int cl_flags)
|
|||
HWND hwnd = 0;
|
||||
unsigned int verify_time = GetTickCount() + 1000;
|
||||
#endif
|
||||
int crc = 0;
|
||||
crc32_t crc = 0;
|
||||
int do_crc = 0;
|
||||
#endif//NSIS_CONFIG_CRC_SUPPORT
|
||||
int left;
|
||||
|
@ -230,9 +229,9 @@ const char * NSISCALL loadHeaders(int cl_flags)
|
|||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
if (do_crc)
|
||||
{
|
||||
int fcrc;
|
||||
crc32_t fcrc;
|
||||
SetSelfFilePointer(m_pos);
|
||||
if (!ReadSelfFile(&fcrc, sizeof(int)) || crc != fcrc)
|
||||
if (!ReadSelfFile(&fcrc, sizeof(crc32_t)) || crc != fcrc)
|
||||
return _LANG_INVALIDCRC;
|
||||
}
|
||||
#endif//NSIS_CONFIG_CRC_SUPPORT
|
||||
|
@ -251,7 +250,7 @@ const char * NSISCALL loadHeaders(int cl_flags)
|
|||
}
|
||||
dbd_srcpos = SetSelfFilePointer(g_filehdrsize + sizeof(firstheader));
|
||||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
dbd_fulllen = dbd_srcpos - sizeof(h) + h.length_of_all_following_data - ((h.flags & FH_FLAGS_NO_CRC) ? 0 : sizeof(int));
|
||||
dbd_fulllen = dbd_srcpos - sizeof(h) + h.length_of_all_following_data - ((h.flags & FH_FLAGS_NO_CRC) ? 0 : sizeof(crc32_t));
|
||||
#else
|
||||
dbd_fulllen = dbd_srcpos - sizeof(h) + h.length_of_all_following_data;
|
||||
#endif//NSIS_CONFIG_CRC_SUPPORT
|
||||
|
|
|
@ -64,7 +64,7 @@ void file_writer_sink::write_data(const void *data, const size_t size)
|
|||
}
|
||||
|
||||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
extern "C" unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len);
|
||||
#include "crc32.h"
|
||||
|
||||
void crc_writer_sink::write_data(const void *data, const size_t size)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "exehead/config.h"
|
||||
#include "growbuf.h"
|
||||
#include "crc32.h"
|
||||
#include <stdio.h>
|
||||
|
||||
class writer_sink {
|
||||
|
@ -57,12 +58,12 @@ private:
|
|||
#ifdef NSIS_CONFIG_CRC_SUPPORT
|
||||
class crc_writer_sink : public writer_sink {
|
||||
public:
|
||||
crc_writer_sink(unsigned long *crc) : m_crc(crc) {}
|
||||
crc_writer_sink(crc32_t *crc) : m_crc(crc) {}
|
||||
|
||||
virtual void write_data(const void *data, const size_t size);
|
||||
|
||||
private:
|
||||
unsigned long *m_crc;
|
||||
crc32_t *m_crc;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue