Skip to content

Commit

Permalink
Update libxls to 1.6.3 (#764)
Browse files Browse the repository at this point in the history
* Naive vendoring of libxls 1.6.3

* Re-apply our usual tweaks

* Start to update config

* Working on unix config

* Remove solaris config

* More work on unix config

* Add more checks in CI

* Revert the r-hub checks, for now

I will follow up on the valgrind result, but don't want to see CI failure in the meantime.

* Update Windows config

* Update notes
  • Loading branch information
jennybc authored Feb 12, 2025
1 parent c7c6850 commit 81f63c6
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 229 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ VignetteBuilder:
Config/Needs/website: tidyverse/tidytemplate, tidyverse
Config/testthat/edition: 3
Encoding: UTF-8
Note: libxls v1.6.2 (patched) 45abe77
Note: libxls v1.6.3 c199d13
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
32 changes: 13 additions & 19 deletions maintenance/01_pull-from-libxls-upstream.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ library(desc)

libxls_path <- "~/rrr/libxls"
there <- function(x) path(libxls_path, x)
target_branch <- "dev" # usually this is master, but not today
target_branch <- "dev" # yeah, this really does appear to be the default

if (git_branch(repo = libxls_path) != target_branch) {
message("YO! You are not on the target branch in libxls!")
}

# relevant when I am embedding an official release
#target_version <- "v1.6.2"
#(tag <- git_tag_list(target_version, repo = libxls_path))
target_version <- "v1.6.3"
(tag <- git_tag_list(target_version, repo = libxls_path))

libxls_SHA <- git_commit_id(repo = libxls_path)

# relevant when I am embedding an official release
# if (tag$commit != libxls_SHA) {
# message("YO! SHA associated with HEAD isn't associated with target version!")
# }
if (tag$commit != libxls_SHA) {
message("YO! SHA associated with HEAD isn't associated with target version!")
}

# the subset of libxls files that we embed
paths <- c(
Expand All @@ -48,26 +48,20 @@ file_copy(
)

# fixup for the case where I'm embedding a dev version
target_version <- "v1.6.2 (patched)"
# target_version <- "v1.6.2 (patched)"
desc::desc_set(Note = paste("libxls", target_version, substr(libxls_SHA, 1, 7)))

# as needed, I rerun the configure script to regenerate
# unix/config.h and windows/config.h

# shortcut from a tip Jim gave long ago:
# download and unpack a libxls release (for windows or *nix) and just run
# ./configure

# as of libxls v1.6.2, we've had to adopt different static config files for
# macOS and other unix (basically motivated by what we see on GHA Ubuntu jobs)

# on windows, you may need to manually & temporarily add the directory
# containing gcc in Rtools to the PATH

# things I needed to do on a fresh Big Sur system to run ./bootstrap
# brew install autoconf
# brew install autoconf-archive
# brew install automake
# brew install gettext
# brew install libtool
# ./bootstrap
# ./configure

# I later learned from Jim that I could also download and unpack the libxls
# release and probably just run ./configure w/o installing so much stuff
# 2025-02-11 Rtools 4.4 this meant adding:
# C:\rtools44\x86_64-w64-mingw32.static.posix\bin
22 changes: 20 additions & 2 deletions src/libxls/xls.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ static xls_error_t xls_mergedCells(xlsWorkSheet* pWS,BOF* bof,BYTE* buf)
return LIBXLS_OK;
}

int xls_isRecordTooSmall(xlsWorkBook *pWB, BOF *bof1) {
int xls_isRecordTooSmall(xlsWorkBook *pWB, BOF *bof1, const BYTE* buf) {
switch (bof1->id) {
case XLS_RECORD_BOF: // BIFF5-8
return (bof1->size < 2 * sizeof(WORD));
Expand All @@ -822,6 +822,24 @@ int xls_isRecordTooSmall(xlsWorkBook *pWB, BOF *bof1) {
return (bof1->size < offsetof(FONT, name));
case XLS_RECORD_FORMAT:
return (bof1->size < offsetof(FORMAT, value));
case XLS_RECORD_STYLE:
{
struct {
unsigned short idx;
unsigned char ident;
unsigned char lvl;
} *styl;
if(bof1->size < 2) {
return 1;
}
styl = (void *)buf;
if(xlsShortVal(styl->idx) & 0x8000) {
return bof1->size < 4;
} else {
if(bof1->size < 3) return 1;
return bof1->size < 3 + styl->ident;
}
}
case XLS_RECORD_1904:
return (bof1->size < sizeof(BYTE));
default:
Expand Down Expand Up @@ -869,7 +887,7 @@ xls_error_t xls_parseWorkBook(xlsWorkBook* pWB)
}
}

if (xls_isRecordTooSmall(pWB, &bof1)) {
if (xls_isRecordTooSmall(pWB, &bof1, buf)) {
retval = LIBXLS_ERROR_PARSE;
goto cleanup;
}
Expand Down
41 changes: 21 additions & 20 deletions src/libxls/xlstool.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,8 @@ char* xls_getCSS(xlsWorkBook* pWB)
DWORD i;

char *ret = malloc(65535);
char *buf = malloc(4096);
size_t buf_len = 4096;
char *buf = malloc(buf_len);
ret[0] = '\0';

for (i=0;i<pWB->xfs.count;i++)
Expand Down Expand Up @@ -780,75 +781,75 @@ char* xls_getCSS(xlsWorkBook* pWB)
switch (xf->linestyle & 0x0f)
{
case 0:
snprintf(borderleft, 255, "%s", "");
snprintf(borderleft, sizeof(borderleft), "%s", "");
break;
default:
snprintf(borderleft, 255, "border-left: 1px solid black;");
snprintf(borderleft, sizeof(borderleft), "border-left: 1px solid black;");
break;
}

switch (xf->linestyle & 0x0f0)
{
case 0:
snprintf(borderright, 255, "%s", "");
snprintf(borderright, sizeof(borderright), "%s", "");
break;
default:
snprintf(borderright, 255, "border-right: 1px solid black;");
snprintf(borderright, sizeof(borderright), "border-right: 1px solid black;");
break;
}

switch (xf->linestyle & 0x0f00)
{
case 0:
snprintf(bordertop, 255, "%s", "");
snprintf(bordertop, sizeof(bordertop), "%s", "");
break;
default:
snprintf(bordertop, 255, "border-top: 1px solid black;");
snprintf(bordertop, sizeof(bordertop), "border-top: 1px solid black;");
break;
}

switch (xf->linestyle & 0x0f000)
{
case 0:
snprintf(borderbottom, 255, "%s", "");
snprintf(borderbottom, sizeof(borderbottom), "%s", "");
break;
default:
snprintf(borderbottom, 255, "border-bottom: 1px solid Black;");
snprintf(borderbottom, sizeof(borderbottom), "border-bottom: 1px solid Black;");
break;
}

if (xf->font)
snprintf(color, 255, "color:#%.6X;",xls_getColor(pWB->fonts.font[xf->font-1].color,0));
snprintf(color, sizeof(color), "color:#%.6X;",xls_getColor(pWB->fonts.font[xf->font-1].color,0));
else
snprintf(color, 255, "%s", "");
snprintf(color, sizeof(color), "%s", "");

if (xf->font && (pWB->fonts.font[xf->font-1].flag & 2))
snprintf(italic, 255, "font-style: italic;");
snprintf(italic, sizeof(italic), "font-style: italic;");
else
snprintf(italic, 255, "%s", "");
snprintf(italic, sizeof(italic), "%s", "");

if (xf->font && (pWB->fonts.font[xf->font-1].bold>400))
snprintf(bold, 255, "font-weight: bold;");
snprintf(bold, sizeof(bold), "font-weight: bold;");
else
snprintf(bold, 255, "%s", "");
snprintf(bold, sizeof(bold), "%s", "");

if (xf->font && (pWB->fonts.font[xf->font-1].underline))
snprintf(underline, 255, "text-decoration: underline;");
snprintf(underline, sizeof(underline), "text-decoration: underline;");
else
snprintf(underline, 255, "%s", "");
snprintf(underline, sizeof(underline), "%s", "");

if (xf->font)
size=pWB->fonts.font[xf->font-1].height/20;
else
size=10;

if (xf->font)
snprintf(fontname, 255,"%s",pWB->fonts.font[xf->font-1].name);
snprintf(fontname, sizeof(fontname),"%s",pWB->fonts.font[xf->font-1].name);
else
snprintf(fontname, 255,"Arial");
snprintf(fontname, sizeof(fontname),"Arial");

background=xls_getColor((WORD)(xf->groundcolor & 0x7f),1);
snprintf(buf, 4096, ".xf%i{ font-size:%ipt;font-family: \"%s\";background:#%.6X;text-align:%s;vertical-align:%s;%s%s%s%s%s%s%s%s}\n",
snprintf(buf, buf_len, ".xf%i{ font-size:%ipt;font-family: \"%s\";background:#%.6X;text-align:%s;vertical-align:%s;%s%s%s%s%s%s%s%s}\n",
i,size,fontname,background,align,valign,borderleft,borderright,bordertop,borderbottom,color,italic,bold,underline);

strcat(ret,buf);
Expand Down
38 changes: 13 additions & 25 deletions src/unix/config-macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#define HAVE_MALLOC 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if your system has a GNU libc compatible `realloc' function,
and to 0 otherwise. */
#define HAVE_REALLOC 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the `strdup' function. */
/* Define to 1 if you have the 'strdup' function. */
#define HAVE_STRDUP 1

/* Define to 1 if you have the <strings.h> header file. */
Expand All @@ -51,7 +43,7 @@
/* Define to 1 if you have the <wchar.h> header file. */
#define HAVE_WCHAR_H 1

/* Define to 1 if you have the `wcstombs_l' function. */
/* Define to 1 if you have the 'wcstombs_l' function. */
#define HAVE_WCSTOMBS_L 1

/* Define to 1 if you have the <xlocale.h> header file. */
Expand All @@ -64,7 +56,7 @@
#define LIBXLS_MAJOR_VERSION 1

/* Micro version */
#define LIBXLS_MICRO_VERSION 2
#define LIBXLS_MICRO_VERSION 3

/* Minor version */
#define LIBXLS_MINOR_VERSION 6
Expand All @@ -82,7 +74,7 @@
#define PACKAGE_NAME "libxls"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libxls 1.6.2"
#define PACKAGE_STRING "libxls 1.6.3"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libxls"
Expand All @@ -91,19 +83,15 @@
#define PACKAGE_URL "https://github.com/libxls/libxls"

/* Define to the version of this package. */
#define PACKAGE_VERSION "1.6.2"
#define PACKAGE_VERSION "1.6.3"

/* Define to 1 if you have the ANSI C header files. */
/* Define to 1 if all of the C89 standard headers exist (not just the ones
required in a freestanding environment). This macro is provided for
backward compatibility; new code need not use it. */
#define STDC_HEADERS 1

/* Version number of package */
#define VERSION "1.6.2"

/* Define to rpl_malloc if the replacement function should be used. */
/* #undef malloc */

/* Define to rpl_realloc if the replacement function should be used. */
/* #undef realloc */
#define VERSION "1.6.3"

/* Define to `unsigned int' if <sys/types.h> does not define. */
/* Define as 'unsigned int' if <stddef.h> doesn't define. */
/* #undef size_t */
Loading

0 comments on commit 81f63c6

Please sign in to comment.