| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
| |
This opens a possibility to selectively disable
particular implementations at runtime.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If static libass is linked into a binary defining functions
of the same name there will be issues. To avoid this use an
ass_ prefix for namespacing.
Before this commit we already did this for most but not yet
all internal API.
read_file is renamed to ass_load_file as ass_read_file
already exists as a public API function. All other functions
are simply prefixed with ass_.
Fixes: https://github.com/libass/libass/issues/222
Fixes: https://github.com/libass/libass/issues/654
|
|
|
|
| |
They are used in multiple files but short enough to inline.
|
|
|
|
|
|
| |
Although declared and defined in ass_utils.{h,c},
those functions are only used in one other file
and aren't useful at other places.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
VSFilter uses the same GetInt method used for colour values
also for all other integer headers and Style or Dialogue
integer fields. This method accepts hexadecimal with a
case-insensitive '&H' or '0x' prefix.
GetInt is practically unchanged from its initial form
in 2003's revision 8 of guliverkli to today's xy*.
(MPC-HC'S ISR changed it more but it still behaves the same wrt to hex)
The previously used atoi never accepts hexadecimal input
and is now only used for the ReadOrder pseudo-field which
isn't parsed by VSFilter.
This relies on uint32_t <-> int32_t conversions just keeping the
bitpattern unchanged (as do many other places in libass) and
mystrtou32_modulo taking sign prefixes into account rather than
rejecting non-positive input.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The two shifts could be used with too large or negative shift operands
which is undefined behaviour. To avoid UB but keep VSFilter
compatibility, simulate the practical effects of such shifts on x86
Windows instead of directly using a simple shift.
The simulated behaviour matches MSYS2's gcc. Clang, gcc and tcc were
observed to exhibit different behaviour on Linux, iff the operand was
a compile-time constant (they would use an arithmetic right shift
instead). Ideally this should be checked against MSVC, but it seems
unlikely to deviate since the related x86 instruction SHL/SAL
is documented to mask the upper three bits of the count operand.
The > 0 check is not present in VSFilter, but we'd like to avoid
negative scales and the only possible negative value is INT32_MIN
i.e. -2^31. Luckily using zero instead of the (font_scale / INT32_MIN)
won't make much difference here.
In guliverkli2 parsed drawing coordinates are also int32_t in canvas
space and only later multiplied by (64 * m_scale{x,y}) where m_scale
combines canvas and drawing scale and is a double. The result is then
cast back to int32_t, meaning coordinates absolutley larger than or
equal to min(2^(25 + draw_scale_exp) / canvas_scale{x,y}, INT32_MAX)
will be turned into INT32_MIN. For the \p32 case this means any drawing
without overflow will be at most 2×2 canvas units large. If only some
coordinates overflow the result can cover more.
In xy-VSFilter drawing coordinates are floating point numbers and parsed
as 64-bit IEEE floats, then multiplied by 64 and cast to int32_t. Here
a truncation already happens before the scaling values are applied,
so any coordinate larger than 2^25 turn into INT32_MIN during initial
parsing. For the \p32 this means a non-overflowing drawing is at most
1/32×1/32 canvas units large.
As a consequence of this parsing difference, drawing coordinates larger
than 2^25 are non-portable showing different behaviour in guliverkli2-
and xy-VSFilter. Thus treating \p32 as an effective \fscx0 seems
unproblematic, since even when scaling the default height of 288
up to a UHD frame size, 1/32×1/32 canvas units don't extend beyond 1/4
pixel, which unless stacked won't be too noticeable.
The remaining left shifts in ass_render.c, should all be safe as they
shift a constant 1 and use macros defined by us as the shift operands
and blur_radius which is limited to 100.
Found by AFL++ and UBSAN.
Samples
assert-fail+shift9999999_fuzzer_w3:id:000159,sig:04,src:000968+000719,time:452375,execs:57769,op:splice,rep:16
shift125_id:000001,sig:04,src:000008+000014,time:526595,execs:18418,op:splice,rep:8
shift-neg_id:000000,sig:04,src:000008+000014,time:466566,execs:18013,op:splice,rep:16
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This continues our transition towards fixed-width types to
improve VSFilter compatibility regardless of the platform libass
is compiled for.
Local variables are also switched to int32_t,
but struct members are left as is for now.
By dropping mystrtoi, which was only used by argtoi, we also fix
float-cast-overflow issues in it identified by UBSAN in libass'
public OSS-Fuzz corpus. mystroi32 does not suffer from this problem.
Sample ID (one instance there are duplicates):
OSSFuzz-123cf9a553c5745854037a52e87947721257f1f3fb
|
|
|
|
| |
mystrtoll was not used since 7913e4a64c704a3b82719d70920b5b153b43d254
|
|
|
|
|
|
|
|
| |
If a higher then supported leaf is requested, at least Intel processors
will silently return the data of the highest supported leaf,
invalidating the following feature tests.
Reported in: https://github.com/libass/libass/pull/603
|
|
|
|
|
|
|
|
|
|
|
| |
We detect x86 and enable building asm code in `configure`.
However, before this commit, we don't actually use that code
unless we detect x86 via the C compiler's predefined macros.
We could check more macros to support more C compilers,
but what we really want is to use the same trigger
for both building and using this code. To that end,
add ARCH_X86 to config.h iff x86 asm is being built.
|
|
|
|
|
|
| |
This is purely an internal refactor.
With the existing and currently planned boolean
features, a bit flag will scale better.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We use %zu format specifiers to log size_t values.
However, __attribute__((format(printf, ...))) in modern GCC means
"system's default" printf, which on MinGW means MSVCRT.DLL printf,
which does not support the z length modifier (even on Windows 10),
so GCC warns that our format strings are invalid.
Older GCC is unable to check Microsoft's format strings at all and
has only format(printf), which is equivalent to the newer gnu_printf.
Clang also lacks gnu_printf, but it is covered by the same macro
check because its __GNUC...__ macros always report version 4.2.1.
On non-Microsoft platforms, printf and gnu_printf are currently
aliases, so the __MINGW32__ check is redundant. However, with some
luck, GCC may start to check other platforms' printf formats more
carefully in the future; and we would like to receive warnings
if our format strings don't work on some platform, although we
intend to stick to standard C99 format strings. Indeed, if we use
an extension by accident, this might help us catch it. And even if
we make no mistake but there is another platform that fails to
support C99 format strings, this might warn some poor soul building
on that platform that their system printf doesn't understand our
log format strings, so they will know they need to work around it
in their log callback or to patch libass.
|
|
|
|
| |
Allows compilers to print warnings when the args we pass don't match the string
|
|
|
|
|
|
| |
M_PI is not part of ISO C and also not part of base POSIX, but an XSI
extension. For simplicity, just always use our own macro for PI.
The value is identical to the one used in glibc and musl.
|
|
|
|
|
|
|
|
| |
And move fallback declarations to ass_compat.h
As ass_compat.h is already included in every source file we no longer
need to include _both_ string.h and ass_utils.h to use str(n)dup.
Definitions are still in ass_utils.c since a separate source file just
for two functions seemed overkill.
|
|
|
|
|
|
| |
Our hash function doesn't handle zero-length buffers,
but it was not a problem until 82b225b3d6653091d028b39d561d185ed76a7be5.
Found by OSS-Fuzz.
|
|
|
|
| |
That eliminates most uses of strdup() in the rendering process.
|
| |
|
|
|
|
| |
Unused since commit c80f332798238731e1ddf1b541748f3d5c8030f3.
|
|
|
|
|
| |
Also makes a measurable difference on float-parse-heavy scripts,
and it's not like these had a reason to not be in the header.
|
| |
|
| |
|
| |
|
|
|
|
| |
This can improve perf somewhat with large bitmaps
|
|
|
|
|
|
|
|
|
|
|
|
| |
This matches the behavior of GDI and hence VSFilter.
Note that \fn arguments are trimmed during parsing.
However, none of the names inside fonts should be trimmed,
and @-prefixed fonts should keep whitespace following the @,
both of which this commit addresses.
Remove strdup_trimmed because it is no longer used. Also remove
the declaration of a function that was deleted a few months ago.
|
|
|
|
|
|
|
|
|
|
|
| |
There is no real value in it. ENCA only works in some cases and I
can't find any information about software that integrates libass
which relies on it or users that rely on ENCA support in case the
interface is exposed directly (e.g. in MPlayer).
If there is still a wish to have charset detection integrated into
libass (it is out of scope, IMHO), a better library like uchardet
should be used for that.
|
|\
| |
| | |
MSVC/ICL and general header fixes
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This way, #include "config.h" is consistently the very
first thing the compiler sees when compiling any file.
Some source files currently don't use anything defined in config.h,
but it's easier and less error-prone to include it now to anticipate
possible future changes in those files, config.h or other headers.
|
|/
|
|
| |
It was needed for UTF16BE -> UTF8 only, which is trivial to implement.
|
| |
|
|
|
|
| |
This is just a cleaner and safer interface for string trimming.
|
|
|
|
| |
Incomplete, leaks memory, but capable of rendering something.
|
|
|
|
|
| |
This adds a trimming utility function that is used for trimming strings
of font requests in the font sorter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Allow exactly one of these prefixes in header values:
0x, 0X, &h, &H. Note that "0x0xFFFFFF" is a correct value,
as the first 0x is consumed by the parser and the second by
the string-to-number conversion following strtol semantics.
* Allow arbitrary numbers of leading & and H
(and not h) in any order in override tag values.
* Reduce header values modulo 2**32 instead
of saturating them to LLONG_MIN/MAX.
* Saturate override tag values to INT32_MIN/MAX
rather than to LLONG_MIN/MAX.
* Don't fiddle with bytes in alpha override tag values.
(They can be outside of the 0..255 range.)
Also change the byte swapping code to be more sensible.
Fixes #80.
Fixes #145.
Fixes #178.
Also fixes our behavior in the case described in
https://code.google.com/p/xy-vsfilter/issues/detail?id=80.
|
| |
|
|
|
|
| |
Oops, trig is hard. We output from -pi to +pi now.
|
|
|
|
| |
Also fix an incorrect comment
|
|
|
|
|
| |
This standard function is not available everywhere, so we detect it and
provide a fallback if missing.
|
|
|
|
|
|
|
|
| |
This actually fixes #146.
The overflow check itself is obvious. Also, make ass_align() return an
unaligned value if aligning it would overflow. This is probably better,
as it for example makes the overflow check in the caller simpler.
|
| |
|
|
|
|
| |
Helps with overflow and allocation failure checking.
|
|
|
|
|
| |
SIZE_MAX is in C99, but not in C89. It is in <stdint.h>, and is always a
macro, so this fallback should be pretty portable and cause no issues.
|
| |
|
| |
|
|
|
|
|
| |
Also replace strtocolor in ass_utils with string2color
from ass.c, because that is more useful everywhere now.
|
| |
|
|
|
|
| |
...instead of doing this manually.
|
|
|
|
| |
Unroll the hash function with Duff's device for improved performance.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
| |
We can rely on fast multiplication and good compilers.
v2: use default FNV-1a prime
Signed-off-by: wm4 <wm4@nowhere>
Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
|
|
|
|
|
| |
Make \rSTYLENAME with an invalid STYLENAME fall back to
line style rather than to Default. This fixes issue #104.
|
|
|
|
|
|
|
|
|
|
|
|
| |
The value is parsed and stored as an enum constant that the consumer
can read from ASS_Track. All output images are still plain RGB,
and the consumer is expected to perform its own color correction.
Supported header values: (TV|PC).(601|709|240M|FCC) and None.
If the header is missing, a special compatibility value is used
that should be treated as TV.601 if the accompanying video stream
is YCbCr and as None otherwise. If the header is present but has
an invalid/unknown value, a different special value is substituted.
|
|
|
|
|
| |
This allows to reset to a certain style, instead of the default style
for the current line. For some reason, this was completely missing.
|
|
|
|
|
|
| |
In hope to make libass as useful as possible, relicense libass to ISC, a
simplified 2-clause BSD license. All contributors who provided
non-trivial changes have granted their permission for this.
|
|
|
|
|
|
| |
In some cases 16.16 precision is not good enough. Instead use 10.22 and
use modulo 360.0 on the angles to make overflows impossible and improve
cache hit ratio sometimes.
|
|
|
|
|
|
|
|
|
| |
strtod respects the locale and in some locales, the decimal separator is
not a point, leading to parsing errors in tags like \pos(23.4,5), which
are perfectly valid.
As there isn't a really portable way to use a particular locale just for
one call to strtod, reimplement it. The implementation was taken from
the 1.8 branch of Ruby.
|
|
|
|
|
|
| |
According to the ASS specification, colors can only be specified in hex.
Modify the color parsing accordingly; this especially means that colors
where the hex sigil (the "H") is missing can now be parsed.
|
|
|
|
|
|
| |
Rename all typedefs from the convention foo_bar_t, which can possibly
conflict with POSIX types, to FooBar (and ASS_FooBar for public
API typedefs). Fix formatting and stray comments while at it.
|
|
|
|
|
| |
Make sure the clip rectangle is inside the screen boundaries.
Idea by Evgeniy Stepanov.
|
|
|
|
|
|
|
|
|
|
|
| |
Introduce functionality for providing a message callback that is used
for passing messages to the controlling application instead of simply
printing them to standard output. The function pointer to the callback
is stored in the ass_library_t instance. ass_msg needs access to it, so
in many places the library instance needs to be passed around now.
The default behavior is the old one: messages of MSGL_INFO or lower
are printed to the standard output, prefixed with "[ass]".
|
|
|
|
|
|
| |
Instead of referencing string defines from help_mp.h, use the strings
directly in ass_msg. Consequently, help_mp.h is useless and can
be deleted.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Finally implement the drawing mode, which allows drawing of custom
vector graphics. Drawings are intercepted in ass_render_event; a hash
of the drawing string is generated which is then used for looking
up drawings and bitmaps of drawings in the cache. The drawings
itself are "fake" glyphs. They are created by parsing the simple
drawing description language, evaluating the curves described (lines,
cubic beziers and/or a special kind of b-splines) and creating vector
outlines. Afterwards, these drawings are (with a few exceptions, e.g.
ascender/descender) exactly handled like regular glyphs.
Support for vector clippings is still missing, but otherwise the
implementation should be complete and compatible with VSFilter.
The libass integration of the drawing parsing/processing code is still a
bit sketchy and should be refactored.
History:
WIP: Drawing mode inf |